From 68858105b2eb11c85105ffac5f32b662c59397f3 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Tue, 1 May 2012 17:06:37 -0800 Subject: [PATCH] + Removed String check for RHS of assert/refute_match. This lets #to_str work properly. Added test_assert_match_matchee_to_str and renamed some tests for clarification. [git-p4: depot-paths = "//src/minitest/dev/": change = 7408] --- lib/minitest/unit.rb | 32 ++++++++++++++++---------------- test/test_minitest_unit.rb | 13 +++++++++++-- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lib/minitest/unit.rb b/lib/minitest/unit.rb index 810e5529..d0e765ab 100644 --- a/lib/minitest/unit.rb +++ b/lib/minitest/unit.rb @@ -270,13 +270,13 @@ def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of end ## - # Fails unless +exp+ is =~ +act+. + # Fails unless +matcher+ =~ +obj+. - def assert_match exp, act, msg = nil - msg = message(msg) { "Expected #{mu_pp(exp)} to match #{mu_pp(act)}" } - assert_respond_to act, :"=~" - exp = Regexp.new Regexp.escape exp if String === exp and String === act - assert exp =~ act, msg + def assert_match matcher, obj, msg = nil + msg = message(msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" } + assert_respond_to matcher, :"=~" + matcher = Regexp.new Regexp.escape matcher if String === matcher + assert matcher =~ obj, msg end ## @@ -521,7 +521,7 @@ def refute_equal exp, act, msg = nil end ## - # For comparing Floats. Fails if +exp+ is within +delta+ of +act+ + # For comparing Floats. Fails if +exp+ is within +delta+ of +act+. # # refute_in_delta Math::PI, (22.0 / 7.0) @@ -542,7 +542,7 @@ def refute_in_epsilon a, b, epsilon = 0.001, msg = nil end ## - # Fails if +collection+ includes +obj+ + # Fails if +collection+ includes +obj+. def refute_includes collection, obj, msg = nil msg = message(msg) { @@ -553,7 +553,7 @@ def refute_includes collection, obj, msg = nil end ## - # Fails if +obj+ is an instance of +cls+ + # Fails if +obj+ is an instance of +cls+. def refute_instance_of cls, obj, msg = nil msg = message(msg) { @@ -563,7 +563,7 @@ def refute_instance_of cls, obj, msg = nil end ## - # Fails if +obj+ is a kind of +cls+ + # Fails if +obj+ is a kind of +cls+. def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" } @@ -571,13 +571,13 @@ def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of end ## - # Fails if +exp+ =~ +act+ + # Fails if +matcher+ =~ +obj+. - def refute_match exp, act, msg = nil - msg = message(msg) { "Expected #{mu_pp(exp)} to not match #{mu_pp(act)}" } - assert_respond_to act, :"=~" - exp = (/#{Regexp.escape exp}/) if String === exp and String === act - refute exp =~ act, msg + def refute_match matcher, obj, msg = nil + msg = message(msg) {"Expected #{mu_pp matcher} to not match #{mu_pp obj}"} + assert_respond_to matcher, :"=~" + matcher = Regexp.new Regexp.escape matcher if String === matcher + refute matcher =~ obj, msg end ## diff --git a/test/test_minitest_unit.rb b/test/test_minitest_unit.rb index af282bbf..0119b759 100755 --- a/test/test_minitest_unit.rb +++ b/test/test_minitest_unit.rb @@ -927,7 +927,7 @@ def test_assert_match @tc.assert_match(/\w+/, "blah blah blah") end - def test_assert_match_object + def test_assert_match_matcher_object @assertion_count = 2 pattern = Object.new @@ -936,6 +936,15 @@ def pattern.=~(other) true end @tc.assert_match pattern, 5 end + def test_assert_match_matchee_to_str + @assertion_count = 2 + + obj = Object.new + def obj.to_str; "blah" end + + @tc.assert_match "blah", obj + end + def test_assert_match_object_triggered @assertion_count = 2 @@ -1454,7 +1463,7 @@ def test_refute_match @tc.refute_match(/\d+/, "blah blah blah") end - def test_refute_match_object + def test_refute_match_matcher_object @assertion_count = 2 @tc.refute_match Object.new, 5 # default #=~ returns false end