Finish of moving the unit tests over to Minitest

This commit is contained in:
Parker Moore 2015-02-21 00:31:07 -08:00
parent 4b59eb4175
commit 52c4ce2a5a
12 changed files with 130 additions and 137 deletions

View File

@ -26,6 +26,7 @@ gem 'jekyll_test_plugin'
gem 'jekyll_test_plugin_malicious' gem 'jekyll_test_plugin_malicious'
gem 'liquid-c', '~> 0.0.3' gem 'liquid-c', '~> 0.0.3'
gem 'minitest' gem 'minitest'
gem 'minitest-reporters'
gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2") gem 'test-unit' if RUBY_PLATFORM =~ /cygwin/ || RUBY_VERSION.start_with?("2.2")
if ENV['BENCHMARK'] if ENV['BENCHMARK']

View File

@ -1,7 +1,6 @@
require 'set' require 'set'
module Jekyll module Jekyll
class Site
# Handles the cleanup of a site's destination before it is built. # Handles the cleanup of a site's destination before it is built.
class Cleaner class Cleaner
attr_reader :site attr_reader :site
@ -99,5 +98,4 @@ module Jekyll
Regexp.new pattern Regexp.new pattern
end end
end end
end
end end

View File

@ -8,6 +8,10 @@ if [ ! -d tmp ]; then
mkdir tmp mkdir tmp
fi fi
if [ -d test/dest ]; then
rm -r test/dest
fi
if [ -z "$1" ]; then if [ -z "$1" ]; then
TEST_FILES=$(ruby -e "puts Dir.glob('test/test_*.rb')") TEST_FILES=$(ruby -e "puts Dir.glob('test/test_*.rb')")
else else

View File

@ -8,6 +8,7 @@ end
require 'rubygems' require 'rubygems'
require 'ostruct' require 'ostruct'
require 'minitest/autorun' require 'minitest/autorun'
require 'minitest/reporters'
require 'jekyll' require 'jekyll'
@ -23,6 +24,9 @@ include Jekyll
# Send STDERR into the void to suppress program output messages # Send STDERR into the void to suppress program output messages
STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:') STDERR.reopen(test(?e, '/dev/null') ? '/dev/null' : 'NUL:')
# Report with color.
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(:color => true)]
class Minitest::Test class Minitest::Test
def fixture_site(overrides = {}) def fixture_site(overrides = {})
Jekyll::Site.new(site_configuration(overrides)) Jekyll::Site.new(site_configuration(overrides))
@ -33,7 +37,10 @@ class Minitest::Test
end end
def site_configuration(overrides = {}) def site_configuration(overrides = {})
full_overrides = build_configs(overrides, build_configs({"destination" => dest_dir})) full_overrides = build_configs(overrides, build_configs({
"destination" => dest_dir,
"full_rebuild" => true
}))
build_configs({ build_configs({
"source" => source_dir "source" => source_dir
}, full_overrides) }, full_overrides)

View File

@ -1,11 +0,0 @@
require 'rubygems'
gem 'test-unit'
require 'test/unit'
# for some reason these tests fail when run via TextMate
# but succeed when run on the command line.
tests = Dir[File.expand_path("#{File.dirname(__FILE__)}/test_*.rb")]
tests.each do |file|
require file
end

View File

@ -12,7 +12,7 @@ class TestCleaner < Minitest::Test
@site = fixture_site @site = fixture_site
@site.keep_files = ['to_keep/child_dir'] @site.keep_files = ['to_keep/child_dir']
@cleaner = Site::Cleaner.new(@site) @cleaner = Cleaner.new(@site)
@cleaner.cleanup! @cleaner.cleanup!
end end
@ -47,7 +47,7 @@ class TestCleaner < Minitest::Test
@site = fixture_site @site = fixture_site
@site.process @site.process
@cleaner = Site::Cleaner.new(@site) @cleaner = Cleaner.new(@site)
@cleaner.cleanup! @cleaner.cleanup!
end end

View File

@ -19,16 +19,16 @@ class TestCoffeeScript < Minitest::Test
return square(x) * x; return square(x) * x;
}; };
cubes = (function() { cubes = (function() {
var _i, _len, _results; var i, len, results;
_results = []; results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) { for (i = 0, len = list.length; i < len; i++) {
num = list[_i]; num = list[i];
_results.push(math.cube(num)); results.push(math.cube(num));
} }
return _results; return results;
})(); })();
if (typeof elvis !== \"undefined\" && elvis !== null) { if (typeof elvis !== "undefined" && elvis !== null) {
return alert(\"I knew it!\"); return alert("I knew it!");
} }
}); });

View File

@ -122,7 +122,7 @@ class TestCollections < Minitest::Test
assert @site.collections["methods"].docs.is_a? Array assert @site.collections["methods"].docs.is_a? Array
@site.collections["methods"].docs.each do |doc| @site.collections["methods"].docs.each do |doc|
assert doc.is_a? Jekyll::Document assert doc.is_a? Jekyll::Document
assert_include %w[ assert_includes %w[
_methods/configuration.md _methods/configuration.md
_methods/sanitized_path.md _methods/sanitized_path.md
_methods/site/generate.md _methods/site/generate.md
@ -135,16 +135,16 @@ class TestCollections < Minitest::Test
end end
should "not include files which start with an underscore in the base collection directory" do should "not include files which start with an underscore in the base collection directory" do
refute_include @collection.filtered_entries, "_do_not_read_me.md" refute_includes @collection.filtered_entries, "_do_not_read_me.md"
end end
should "not include files which start with an underscore in a subdirectory" do should "not include files which start with an underscore in a subdirectory" do
refute_include @collection.filtered_entries, "site/_dont_include_me_either.md" refute_includes @collection.filtered_entries, "site/_dont_include_me_either.md"
end end
should "not include the underscored files in the list of docs" do should "not include the underscored files in the list of docs" do
refute_include @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md" refute_includes @collection.docs.map(&:relative_path), "_methods/_do_not_read_me.md"
refute_include @collection.docs.map(&:relative_path), "_methods/site/_dont_include_me_either.md" refute_includes @collection.docs.map(&:relative_path), "_methods/site/_dont_include_me_either.md"
end end
end end
@ -178,12 +178,12 @@ class TestCollections < Minitest::Test
end end
should "not allow symlinks" do should "not allow symlinks" do
refute_include @collection.filtered_entries, "um_hi.md" refute_includes @collection.filtered_entries, "um_hi.md"
refute_include @collection.filtered_entries, "/um_hi.md" refute_includes @collection.filtered_entries, "/um_hi.md"
end end
should "not include the symlinked file in the list of docs" do should "not include the symlinked file in the list of docs" do
refute_include @collection.docs.map(&:relative_path), "_methods/um_hi.md" refute_includes @collection.docs.map(&:relative_path), "_methods/um_hi.md"
end end
end end

View File

@ -84,14 +84,12 @@ OUTPUT
end end
should "acceptable limit post is 0" do should "acceptable limit post is 0" do
refute_raises ArgumentError do
clear_dest clear_dest
stub(Jekyll).configuration do stub(Jekyll).configuration do
Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0}) Jekyll::Configuration::DEFAULTS.merge({'source' => source_dir, 'destination' => dest_dir, 'limit_posts' => 0})
end end
@site = Site.new(Jekyll.configuration) assert Site.new(Jekyll.configuration), "Couldn't create a site with the given limit_posts."
end
end end
end end
end end

View File

@ -79,9 +79,8 @@ class TestNewCommand < Minitest::Test
should 'force created folder' do should 'force created folder' do
capture_stdout { Jekyll::Commands::New.process(@args) } capture_stdout { Jekyll::Commands::New.process(@args) }
refute_raises(SystemExit) do output = capture_stdout { Jekyll::Commands::New.process(@args, '--force') }
capture_stdout {Jekyll::Commands::New.process(@args, '--force') } assert_match /New jekyll site installed in/, output
end
end end
end end

View File

@ -10,7 +10,8 @@ class TestRegenerator < Minitest::Test
"methods" => { "methods" => {
"output" => true "output" => true
} }
} },
"full_rebuild" => false
}) })
@site.read @site.read

View File

@ -309,9 +309,7 @@ class TestSite < Minitest::Test
custom_processor = "CustomMarkdown" custom_processor = "CustomMarkdown"
s = Site.new(site_configuration('markdown' => custom_processor)) s = Site.new(site_configuration('markdown' => custom_processor))
refute_raises do assert !!s.process
s.process
end
# Do some cleanup, we don't like straggling stuff's. # Do some cleanup, we don't like straggling stuff's.
Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown) Jekyll::Converters::Markdown.send(:remove_const, :CustomMarkdown)
@ -344,9 +342,7 @@ class TestSite < Minitest::Test
context 'with an invalid markdown processor in the configuration' do context 'with an invalid markdown processor in the configuration' do
should 'not throw an error at initialization time' do should 'not throw an error at initialization time' do
bad_processor = 'not a processor name' bad_processor = 'not a processor name'
refute_raises do assert Site.new(site_configuration('markdown' => bad_processor))
Site.new(site_configuration('markdown' => bad_processor))
end
end end
should 'throw FatalException at process time' do should 'throw FatalException at process time' do