test: use {assert,refute}_exist everywhere

This commit is contained in:
Parker Moore 2016-01-18 13:45:36 -08:00
parent 2de5bacb41
commit 275d56a0fe
7 changed files with 58 additions and 51 deletions

View File

@ -21,19 +21,19 @@ class TestCleaner < JekyllUnitTest
end end
should "keep the parent directory" do should "keep the parent directory" do
assert File.exist?(dest_dir('to_keep')) assert_exist dest_dir('to_keep')
end end
should "keep the child directory" do should "keep the child directory" do
assert File.exist?(dest_dir('to_keep/child_dir')) assert_exist dest_dir('to_keep', 'child_dir')
end end
should "keep the file in the directory in keep_files" do should "keep the file in the directory in keep_files" do
assert File.exist?(File.join(dest_dir('to_keep/child_dir'), 'index.html')) assert_exist dest_dir('to_keep', 'child_dir', 'index.html')
end end
should "delete the file in the directory not in keep_files" do should "delete the file in the directory not in keep_files" do
assert !File.exist?(File.join(dest_dir('to_keep'), 'index.html')) refute_exist dest_dir('to_keep', 'index.html')
end end
end end
@ -41,8 +41,8 @@ class TestCleaner < JekyllUnitTest
setup do setup do
clear_dest clear_dest
FileUtils.mkdir_p(source_dir('no_files_inside/child_dir')) FileUtils.mkdir_p(source_dir('no_files_inside', 'child_dir'))
FileUtils.touch(File.join(source_dir('no_files_inside/child_dir'), 'index.html')) FileUtils.touch(source_dir('no_files_inside', 'child_dir', 'index.html'))
@site = fixture_site @site = fixture_site
@site.process @site.process
@ -57,15 +57,15 @@ class TestCleaner < JekyllUnitTest
end end
should "keep the parent directory" do should "keep the parent directory" do
assert File.exist?(dest_dir('no_files_inside')) assert_exist dest_dir('no_files_inside')
end end
should "keep the child directory" do should "keep the child directory" do
assert File.exist?(dest_dir('no_files_inside/child_dir')) assert_exist dest_dir('no_files_inside', 'child_dir')
end end
should "keep the file" do should "keep the file" do
assert File.exist?(File.join(dest_dir('no_files_inside/child_dir'), 'index.html')) assert_exist source_dir('no_files_inside', 'child_dir', 'index.html')
end end
end end
end end

View File

@ -37,7 +37,7 @@ JS
end end
should "write a JS file in place" do should "write a JS file in place" do
assert File.exist?(@test_coffeescript_file), "Can't find the converted CoffeeScript file in the dest_dir." assert_exist @test_coffeescript_file, "Can't find the converted CoffeeScript file in the dest_dir."
end end
should "produce JS" do should "produce JS" do

View File

@ -31,17 +31,17 @@ class TestGeneratedSite < JekyllUnitTest
end end
should "hide unpublished page" do should "hide unpublished page" do
assert !File.exist?(dest_dir('/unpublished.html')) refute_exist dest_dir('/unpublished.html')
end end
should "not copy _posts directory" do should "not copy _posts directory" do
assert !File.exist?(dest_dir('_posts')) refute_exist dest_dir('_posts')
end end
should "process other static files and generate correct permalinks" do should "process other static files and generate correct permalinks" do
assert File.exist?(dest_dir('/about/index.html')), "about/index.html should exist" assert_exist dest_dir('about', 'index.html'), "about/index.html should exist"
assert File.exist?(dest_dir('/contacts.html')), "contacts.html should exist" assert_exist dest_dir('contacts.html'), "contacts.html should exist"
assert File.exist?(dest_dir('/dynamic_file.php')), "dynamic_file.php should exist" assert_exist dest_dir('dynamic_file.php'), "dynamic_file.php should exist"
end end
should "print a nice list of static files" do should "print a nice list of static files" do
@ -72,15 +72,22 @@ OUTPUT
should "ensure limit posts is 0 or more" do should "ensure limit posts is 0 or more" do
assert_raises ArgumentError do assert_raises ArgumentError do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => -1}) config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir,
'destination' => dest_dir,
'limit_posts' => -1
})
@site = fixture_site(config) @site = fixture_site(config)
end end
end end
should "acceptable limit post is 0" do should "acceptable limit post is 0" do
clear_dest clear_dest
config = Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) config = Jekyll::Configuration::DEFAULTS.merge({
'source' => source_dir,
'destination' => dest_dir,
'limit_posts' => 0
})
assert Site.new(config), "Couldn't create a site with the given limit_posts." assert Site.new(config), "Couldn't create a site with the given limit_posts."
end end

View File

@ -24,9 +24,9 @@ class TestNewCommand < JekyllUnitTest
end end
should 'create a new directory' do should 'create a new directory' do
assert !File.exist?(@full_path) refute_exist @full_path
Jekyll::Commands::New.process(@args) Jekyll::Commands::New.process(@args)
assert File.exist?(@full_path) assert_exist @full_path
end end
should 'display a success message' do should 'display a success message' do
@ -96,9 +96,9 @@ class TestNewCommand < JekyllUnitTest
end end
should 'create a new directory' do should 'create a new directory' do
assert !File.exist?(@site_name_with_spaces) refute_exist @site_name_with_spaces
capture_stdout { Jekyll::Commands::New.process(@multiple_args) } capture_stdout { Jekyll::Commands::New.process(@multiple_args) }
assert File.exist?(@site_name_with_spaces) assert_exist @site_name_with_spaces
end end
end end

View File

@ -213,7 +213,7 @@ class TestPage < JekyllUnitTest
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert !File.exist?(unexpected) refute_exist unexpected
end end
end end
@ -238,7 +238,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts.html')) assert_exist dest_dir('contacts.html')
end end
should "write even when the folder name is plus and permalink has +" do should "write even when the folder name is plus and permalink has +" do
@ -246,8 +246,8 @@ class TestPage < JekyllUnitTest
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir), "#{dest_dir} should be a directory"
assert File.exist?(File.join(dest_dir, '+', 'plus+in+url.html')) assert_exist dest_dir('+', 'plus+in+url.html')
end end
should "write even when permalink has '%# +'" do should "write even when permalink has '%# +'" do
@ -256,7 +256,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, '+', '%# +.html')) assert_exist dest_dir('+', '%# +.html')
end end
should "write properly without html extension" do should "write properly without html extension" do
@ -266,7 +266,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'index.html')) assert_exist dest_dir('contacts', 'index.html')
end end
should "support .htm extension and respects that" do should "support .htm extension and respects that" do
@ -276,7 +276,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'index.htm')) assert_exist dest_dir('contacts', 'index.htm')
end end
should "support .xhtml extension and respects that" do should "support .xhtml extension and respects that" do
@ -286,7 +286,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'index.xhtml')) assert_exist dest_dir('contacts', 'index.xhtml')
end end
should "write properly with extension different from html" do should "write properly with extension different from html" do
@ -295,10 +295,10 @@ class TestPage < JekyllUnitTest
do_render(page) do_render(page)
page.write(dest_dir) page.write(dest_dir)
assert_equal("/sitemap.xml", page.url) assert_equal "/sitemap.xml", page.url
assert_nil(page.url[/\.html$/]) assert_nil page.url[/\.html$/]
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir,'sitemap.xml')) assert_exist dest_dir('sitemap.xml')
end end
should "write dotfiles properly" do should "write dotfiles properly" do
@ -307,7 +307,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, '.htaccess')) assert_exist dest_dir('.htaccess')
end end
context "in a directory hierarchy" do context "in a directory hierarchy" do
@ -317,7 +317,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'index.html')) assert_exist dest_dir('contacts', 'index.html')
end end
should "write properly" do should "write properly" do
@ -326,7 +326,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'bar.html')) assert_exist dest_dir('contacts', 'bar.html')
end end
should "write properly without html extension" do should "write properly without html extension" do
@ -336,7 +336,7 @@ class TestPage < JekyllUnitTest
page.write(dest_dir) page.write(dest_dir)
assert File.directory?(dest_dir) assert File.directory?(dest_dir)
assert File.exist?(File.join(dest_dir, 'contacts', 'bar', 'index.html')) assert_exist dest_dir('contacts', 'bar', 'index.html')
end end
end end
end end

View File

@ -112,7 +112,7 @@ class TestRegenerator < JekyllUnitTest
assert_equal 1, @regenerator.metadata.size assert_equal 1, @regenerator.metadata.size
path = @regenerator.metadata.keys[0] path = @regenerator.metadata.keys[0]
assert File.exist?(@layout_path) assert_exist @layout_path
@regenerator.add_dependency(path, @layout_path) @regenerator.add_dependency(path, @layout_path)
File.rename(@layout_path, @layout_path + ".tmp") File.rename(@layout_path, @layout_path + ".tmp")

View File

@ -275,25 +275,25 @@ class TestSite < JekyllUnitTest
should 'remove orphaned files in destination' do should 'remove orphaned files in destination' do
@site.process @site.process
assert !File.exist?(dest_dir('obsolete.html')) refute_exist dest_dir('obsolete.html')
assert !File.exist?(dest_dir('qux')) refute_exist dest_dir('qux')
assert !File.exist?(dest_dir('quux')) refute_exist dest_dir('quux')
assert File.exist?(dest_dir('.git')) assert_exist dest_dir('.git')
assert File.exist?(dest_dir('.git/HEAD')) assert_exist dest_dir('.git', 'HEAD')
end end
should 'remove orphaned files in destination - keep_files .svn' do should 'remove orphaned files in destination - keep_files .svn' do
config = site_configuration('keep_files' => %w{.svn}) config = site_configuration('keep_files' => %w{.svn})
@site = Site.new(config) @site = Site.new(config)
@site.process @site.process
assert !File.exist?(dest_dir('.htpasswd')) refute_exist dest_dir('.htpasswd')
assert !File.exist?(dest_dir('obsolete.html')) refute_exist dest_dir('obsolete.html')
assert !File.exist?(dest_dir('qux')) refute_exist dest_dir('qux')
assert !File.exist?(dest_dir('quux')) refute_exist dest_dir('quux')
assert !File.exist?(dest_dir('.git')) refute_exist dest_dir('.git')
assert !File.exist?(dest_dir('.git/HEAD')) refute_exist dest_dir('.git', 'HEAD')
assert File.exist?(dest_dir('.svn')) assert_exist dest_dir('.svn')
assert File.exist?(dest_dir('.svn/HEAD')) assert_exist dest_dir('.svn', 'HEAD')
end end
end end