Permalink
Browse files

+ 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]
  • Loading branch information...
1 parent 85f8f77 commit 68858105b2eb11c85105ffac5f32b662c59397f3 @zenspider zenspider committed May 2, 2012
Showing with 27 additions and 18 deletions.
  1. +16 −16 lib/minitest/unit.rb
  2. +11 −2 test/test_minitest_unit.rb
View
@@ -270,13 +270,13 @@ def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
end
##
- # Fails unless +exp+ is <tt>=~</tt> +act+.
+ # Fails unless +matcher+ <tt>=~</tt> +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,21 +563,21 @@ 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}" }
refute obj.kind_of?(cls), msg
end
##
- # Fails if +exp+ <tt>=~</tt> +act+
+ # Fails if +matcher+ <tt>=~</tt> +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
##
View
@@ -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

0 comments on commit 6885810

Please sign in to comment.