diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-23 21:47:25 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-08-23 21:47:25 +0000 |
commit | 2c43b9664b29f76c73ac8bae5400b79d0a5313e0 (patch) | |
tree | 6e9b4a581ac460c38d22de2750939fa815a98295 /test/minitest/test_minitest_unit.rb | |
parent | 885f5fa2b0c1ba20a26759e65fefeece48cb56db (diff) | |
download | ruby-2c43b9664b29f76c73ac8bae5400b79d0a5313e0.tar.gz |
Imported minitest 2.5.0 (r6557)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/minitest/test_minitest_unit.rb')
-rw-r--r-- | test/minitest/test_minitest_unit.rb | 151 |
1 files changed, 150 insertions, 1 deletions
diff --git a/test/minitest/test_minitest_unit.rb b/test/minitest/test_minitest_unit.rb index b56fb0dc18..c921ca749e 100644 --- a/test/minitest/test_minitest_unit.rb +++ b/test/minitest/test_minitest_unit.rb @@ -12,6 +12,7 @@ MiniTest::Unit.autorun module MyModule; end class AnError < StandardError; include MyModule; end +class ImmutableString < String; def inspect; super.freeze; end; end class TestMiniTestUnit < MiniTest::Unit::TestCase pwd = Pathname.new(File.expand_path(Dir.pwd)) @@ -46,12 +47,12 @@ Finished tests in 0.00 MiniTest::Unit::TestCase.reset @tu = MiniTest::Unit.new @output = StringIO.new("") + MiniTest::Unit.runner = nil # protect the outer runner from the inner tests MiniTest::Unit.output = @output end def teardown MiniTest::Unit.output = $stdout - MiniTest::Unit.runner = nil Object.send :remove_const, :ATestCase if defined? ATestCase end @@ -442,6 +443,149 @@ Finished tests in 0.00 assert_report expected end + def with_overridden_include + Class.class_eval do + def inherited_with_hacks klass + throw :inherited_hook + end + + alias inherited_without_hacks inherited + alias inherited inherited_with_hacks + alias IGNORE_ME! inherited # 1.8 bug. god I love venture bros + end + + yield + + ensure + Class.class_eval do + alias inherited inherited_without_hacks + + undef_method :inherited_with_hacks + undef_method :inherited_without_hacks + end + + refute_respond_to Class, :inherited_with_hacks + refute_respond_to Class, :inherited_without_hacks + end + + def test_inherited_hook_plays_nice_with_others + with_overridden_include do + assert_throws :inherited_hook do + Class.new MiniTest::Unit::TestCase + end + end + end + + def test_setup_hooks + call_order = [] + + tc = Class.new(MiniTest::Unit::TestCase) do + define_method :setup do + super() + call_order << :method + end + + define_method :test2 do + call_order << :test2 + end + + define_method :test1 do + call_order << :test1 + end + end + + tc.add_setup_hook lambda { call_order << :proc } + + argument = nil + + tc.add_setup_hook do |arg| + argument = arg + call_order << :block + end + + @tu.run %w[--seed 42] + + assert_kind_of tc, argument + + expected = [:method, :proc, :block, :test1, + :method, :proc, :block, :test2] + + assert_equal expected, call_order + end + + def test_teardown_hooks + call_order = [] + + tc = Class.new(MiniTest::Unit::TestCase) do + define_method :teardown do + super() + call_order << :method + end + + define_method :test2 do + call_order << :test2 + end + + define_method :test1 do + call_order << :test1 + end + end + + tc.add_teardown_hook lambda { call_order << :proc } + + argument = nil + + tc.add_teardown_hook do |arg| + argument = arg + call_order << :block + end + + @tu.run %w[--seed 42] + + assert_kind_of tc, argument + + expected = [:test1, :block, :proc, :method, + :test2, :block, :proc, :method] + + assert_equal expected, call_order + end + + def test_setup_and_teardown_hooks_survive_inheritance + call_order = [] + + parent = Class.new(MiniTest::Unit::TestCase) do + define_method :setup do + super() + call_order << :setup_method + end + + define_method :teardown do + super() + call_order << :teardown_method + end + + define_method :test_something do + call_order << :test + end + end + + parent.add_setup_hook { call_order << :setup_hook } + parent.add_teardown_hook { call_order << :teardown_hook } + + _ = Class.new parent + + parent.add_setup_hook { call_order << :setup_after } + parent.add_teardown_hook { call_order << :teardown_after } + + @tu.run %w[--seed 42] + + # Once for the parent class, once for the child + expected = [:setup_method, :setup_hook, :setup_after, :test, + :teardown_after, :teardown_hook, :teardown_method] * 2 + + assert_equal expected, call_order + end + def util_expand_bt bt if RUBY_VERSION =~ /^1\.9/ then bt.map { |f| (f =~ /^\./) ? File.expand_path(f) : f } @@ -1084,6 +1228,11 @@ FILE:LINE:in `test_assert_raises_triggered_subclass' @tc.pass end + def test_prints + printer = Class.new { extend MiniTest::Assertions } + @tc.assert_equal '"test"', printer.mu_pp(ImmutableString.new 'test') + end + def test_refute @assertion_count = 2 |