ruby-changes:9591
From: yugui <ko1@a...>
Date: Sun, 28 Dec 2008 18:43:21 +0900 (JST)
Subject: [ruby-changes:9591] Ruby:r21131 (ruby_1_9_1): merges r21104 from trunk into ruby_1_9_1.
yugui 2008-12-28 18:42:51 +0900 (Sun, 28 Dec 2008) New Revision: 21131 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=21131 Log: merges r21104 from trunk into ruby_1_9_1. * Imported minitest 1.3.1 r4505. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/lib/minitest/spec.rb branches/ruby_1_9_1/lib/minitest/unit.rb branches/ruby_1_9_1/test/minitest/test_mini_spec.rb branches/ruby_1_9_1/test/minitest/test_mini_test.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 21130) +++ ruby_1_9_1/ChangeLog (revision 21131) @@ -1,3 +1,8 @@ +Sun Dec 28 05:44:44 2008 Ryan Davis <ryan@w...> + + * lib/minitest/*.rb: Imported minitest 1.3.1 r4505. + * test/minitest/*.rb: ditto. + Sun Dec 28 00:43:33 2008 Tanaka Akira <akr@f...> * runruby.rb: refactored to modify ENV as once. @@ -1022,7 +1027,7 @@ Sat Dec 13 09:17:33 2008 Ryan Davis <ryand-ruby@z...> - * lib/minitest/*.rb: Imported minitest 1.3.2 r4503. + * lib/minitest/*.rb: Imported minitest 1.3.1 r4503. * test/minitest/test_mini_test.rb: ditto. * lib/miniunit/autorun.rb: added (as part of r4503). Index: ruby_1_9_1/lib/minitest/unit.rb =================================================================== --- ruby_1_9_1/lib/minitest/unit.rb (revision 21130) +++ ruby_1_9_1/lib/minitest/unit.rb (revision 21131) @@ -116,9 +116,9 @@ end def assert_match exp, act, msg = nil - msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" } + msg = message(msg) { "Expected #{mu_pp(exp)} to match #{mu_pp(act)}" } assert_respond_to act, :"=~" - (exp = /#{Regexp.escape(exp)}/) if String === exp && String === act + exp = /#{Regexp.escape(exp)}/ if String === exp && String === act assert act =~ exp, msg end @@ -269,7 +269,7 @@ msg = message(msg) { "Expected #{mu_pp(obj)} to not be an instance of #{cls}" } flip = (Module === obj) && ! (Module === cls) # HACK for specs obj, cls = cls, obj if flip - refute cls === obj, msg + refute obj.instance_of?(cls), msg end def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of @@ -280,7 +280,9 @@ end def refute_match exp, act, msg = nil - msg = message(msg) { "Expected #{mu_pp(act)} to not match #{mu_pp(exp)}" } + msg = message(msg) { "Expected #{mu_pp(exp)} to not match #{mu_pp(act)}" } + assert_respond_to act, :"=~" + exp = /#{Regexp.escape(exp)}/ if String === exp && String === act refute act =~ exp, msg end @@ -313,7 +315,7 @@ end class Unit - VERSION = "1.3.2" + VERSION = "1.3.1" attr_accessor :report, :failures, :errors, :skips attr_accessor :test_count, :assertion_count @@ -323,7 +325,6 @@ def self.autorun at_exit { -p $! return if $! # don't run if there was an exception exit_code = MiniTest::Unit.new.run(ARGV) exit false if exit_code && exit_code != 0 @@ -336,9 +337,12 @@ end def location e - e.backtrace.find { |s| - s !~ /in .(assert|refute|flunk|pass|fail|raise)/ - }.sub(/:in .*$/, '') + last_before_assertion = "" + e.backtrace.reverse_each do |s| + break if s =~ /in .(assert|refute|flunk|pass|fail|raise)/ + last_before_assertion = s + end + last_before_assertion.sub(/:in .*$/, '') end def puke klass, meth, e Index: ruby_1_9_1/lib/minitest/spec.rb =================================================================== --- ruby_1_9_1/lib/minitest/spec.rb (revision 21130) +++ ruby_1_9_1/lib/minitest/spec.rb (revision 21131) @@ -60,6 +60,7 @@ cls.class_eval(&block) end + private :describe end class MiniTest::Spec < MiniTest::Unit::TestCase Index: ruby_1_9_1/test/minitest/test_mini_spec.rb =================================================================== --- ruby_1_9_1/test/minitest/test_mini_spec.rb (revision 21130) +++ ruby_1_9_1/test/minitest/test_mini_spec.rb (revision 21131) @@ -140,6 +140,7 @@ end it "needs to verify mismatch" do + @assertion_count = 6 "blah".wont_match(/\d+/).must_equal false proc { "blah".wont_match(/\w+/) }.must_raise MiniTest::Assertion end Index: ruby_1_9_1/test/minitest/test_mini_test.rb =================================================================== --- ruby_1_9_1/test/minitest/test_mini_test.rb (revision 21130) +++ ruby_1_9_1/test/minitest/test_mini_test.rb (revision 21131) @@ -28,7 +28,7 @@ Object.send :remove_const, :ATestCase if defined? ATestCase end - pwd = Pathname.new(File.expand_path Dir.pwd) + pwd = Pathname.new(File.expand_path(Dir.pwd)) basedir = Pathname.new(File.expand_path(MiniTest::MINI_DIR)) + 'mini' basedir = basedir.relative_path_from(pwd).to_s MINITEST_BASE_DIR = basedir[/\A\./] ? basedir : "./#{basedir}" @@ -96,6 +96,7 @@ assert_equal 'F', @tu.puke('SomeClass', 'method_name', exception) assert_equal 1, @tu.failures assert_match(/^Failure.*Oh no!/m, @tu.report.first) + assert_match("method_name(SomeClass) [unhappy]", @tu.report.first) end def test_class_puke_with_failure_and_flunk_in_backtrace @@ -108,6 +109,72 @@ refute @tu.report.any?{|line| line =~ /in .flunk/} end + def test_class_puke_with_assertion_failed_and_long_backtrace + bt = (["test/test_some_class.rb:615:in `method_name'", + "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", + "test/test_some_class.rb:615:in `each'", + "test/test_some_class.rb:614:in `test_method_name'", + "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + + BT_MIDDLE + + ["#{MINITEST_BASE_DIR}/test.rb:29"]) + bt = util_expand_bt bt + + ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first + + exception = MiniTest::Assertion.new "Oh no!" + exception.set_backtrace bt + assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) + assert_equal 1, @tu.failures + assert_match(/^Failure.*Oh no!/m, @tu.report.first) + assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first) + end + + def test_class_puke_with_assertion_failed_and_user_defined_assertions + bt = (["lib/test/my/util.rb:16:in `another_method_name'", + "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", + "lib/test/my/util.rb:15:in `block in assert_something'", + "lib/test/my/util.rb:14:in `each'", + "lib/test/my/util.rb:14:in `assert_something'", + "test/test_some_class.rb:615:in `each'", + "test/test_some_class.rb:614:in `test_method_name'", + "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + + BT_MIDDLE + + ["#{MINITEST_BASE_DIR}/test.rb:29"]) + bt = util_expand_bt bt + + ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first + + exception = MiniTest::Assertion.new "Oh no!" + exception.set_backtrace bt + assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) + assert_equal 1, @tu.failures + assert_match(/^Failure.*Oh no!/m, @tu.report.first) + assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first) + end + + def test_class_puke_with_flunk_and_user_defined_assertions + bt = (["lib/test/my/util.rb:16:in `flunk'", + "#{MINITEST_BASE_DIR}/unit.rb:140:in `assert_raises'", + "lib/test/my/util.rb:15:in `block in assert_something'", + "lib/test/my/util.rb:14:in `each'", + "lib/test/my/util.rb:14:in `assert_something'", + "test/test_some_class.rb:615:in `each'", + "test/test_some_class.rb:614:in `test_method_name'", + "#{MINITEST_BASE_DIR}/test.rb:165:in `__send__'"] + + BT_MIDDLE + + ["#{MINITEST_BASE_DIR}/test.rb:29"]) + bt = util_expand_bt bt + + ex_location = util_expand_bt(["test/test_some_class.rb:615"]).first + + exception = MiniTest::Assertion.new "Oh no!" + exception.set_backtrace bt + assert_equal 'F', @tu.puke('TestSomeClass', 'test_method_name', exception) + assert_equal 1, @tu.failures + assert_match(/^Failure.*Oh no!/m, @tu.report.first) + assert_match("test_method_name(TestSomeClass) [#{ex_location}]", @tu.report.first) + end + def test_class_puke_with_non_failure_exception exception = Exception.new("Oh no again!") assert_equal 'E', @tu.puke('SomeClass', 'method_name', exception) @@ -465,13 +532,13 @@ def test_assert_match @assertion_count = 2 - @tc.assert_match "blah blah blah", /\w+/ + @tc.assert_match(/\w+/, "blah blah blah") end def test_assert_match_triggered @assertion_count = 2 util_assert_triggered 'Expected /\d+/ to match "blah blah blah".' do - @tc.assert_match "blah blah blah", /\d+/ + @tc.assert_match(/\d+/, "blah blah blah") end end @@ -795,12 +862,14 @@ end def test_refute_match - @tc.refute_match "blah blah blah", /\d+/ + @assertion_count = 2 + @tc.refute_match(/\d+/, "blah blah blah") end def test_refute_match_triggered + @assertion_count = 2 util_assert_triggered 'Expected /\w+/ to not match "blah blah blah".' do - @tc.refute_match "blah blah blah", /\w+/ + @tc.refute_match(/\w+/, "blah blah blah") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/