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
should "keep the parent directory" do
assert File.exist?(dest_dir('to_keep'))
assert_exist dest_dir('to_keep')
end
should "keep the child directory" do
assert File.exist?(dest_dir('to_keep/child_dir'))
assert_exist dest_dir('to_keep', 'child_dir')
end
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
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
@ -41,8 +41,8 @@ class TestCleaner < JekyllUnitTest
setup do
clear_dest
FileUtils.mkdir_p(source_dir('no_files_inside/child_dir'))
FileUtils.touch(File.join(source_dir('no_files_inside/child_dir'), 'index.html'))
FileUtils.mkdir_p(source_dir('no_files_inside', 'child_dir'))
FileUtils.touch(source_dir('no_files_inside', 'child_dir', 'index.html'))
@site = fixture_site
@site.process
@ -57,15 +57,15 @@ class TestCleaner < JekyllUnitTest
end
should "keep the parent directory" do
assert File.exist?(dest_dir('no_files_inside'))
assert_exist dest_dir('no_files_inside')
end
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
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

View File

@ -37,7 +37,7 @@ JS
end
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
should "produce JS" do

View File

@ -31,17 +31,17 @@ class TestGeneratedSite < JekyllUnitTest
end
should "hide unpublished page" do
assert !File.exist?(dest_dir('/unpublished.html'))
refute_exist dest_dir('/unpublished.html')
end
should "not copy _posts directory" do
assert !File.exist?(dest_dir('_posts'))
refute_exist dest_dir('_posts')
end
should "process other static files and generate correct permalinks" do
assert File.exist?(dest_dir('/about/index.html')), "about/index.html should exist"
assert File.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('about', 'index.html'), "about/index.html should exist"
assert_exist dest_dir('contacts.html'), "contacts.html should exist"
assert_exist dest_dir('dynamic_file.php'), "dynamic_file.php should exist"
end
should "print a nice list of static files" do
@ -72,15 +72,22 @@ OUTPUT
should "ensure limit posts is 0 or more" do
assert_raises ArgumentError do
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)
end
end
should "acceptable limit post is 0" do
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."
end

View File

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

View File

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

View File

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

View File

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