Regenerator cache clearing tests

Two tests for the regenerator cache clearing changes:

1. Intrusively test that the regnerator.clear_cache actually clears the cache ( in test/test_regenerator.rb )
2. Test that incremental building regenerates files that have changed that previously were unchanged ( in test/test_site.rb )
This commit is contained in:
Nicholas Burlett 2015-03-19 09:41:05 -07:00
parent 15ebf929e1
commit e770a080a7
2 changed files with 47 additions and 0 deletions

View File

@ -75,6 +75,15 @@ class TestRegenerator < JekyllUnitTest
assert @regenerator.cache[@path]
end
should "clear the cache on clear_cache" do
# @path will be in the cache because the
# site will have processed it
assert @regenerator.cache[@path]
@regenerator.clear_cache
assert_equal @regenerator.cache, {}
end
should "write to the metadata file" do
@regenerator.clear
@regenerator.add(@path)

View File

@ -459,5 +459,43 @@ class TestSite < JekyllUnitTest
end
end
context "incremental build" do
setup do
@site = Site.new(site_configuration({
'full_rebuild' => false
}))
@site.read
end
should "build incrementally" do
contacts_html = @site.pages.find { |p| p.name == "contacts.html" }
@site.process
source = @site.in_source_dir(contacts_html.path)
dest = File.expand_path(contacts_html.destination(@site.dest))
mtime1 = File.stat(dest).mtime.to_i # first run must generate dest file
# need to sleep because filesystem timestamps have best resolution in seconds
sleep 1
@site.process
mtime2 = File.stat(dest).mtime.to_i
assert_equal mtime1, mtime2 # no modifications, so remain the same
# simulate file modification by user
FileUtils.touch source
sleep 1
@site.process
mtime3 = File.stat(dest).mtime.to_i
refute_equal mtime2, mtime3 # must be regenerated
sleep 1
@site.process
mtime4 = File.stat(dest).mtime.to_i
assert_equal mtime3, mtime4 # no modifications, so remain the same
end
end
end
end