Skip to content

Commit

Permalink
+ Removed String check for RHS of assert/refute_match. This lets #to_…
Browse files Browse the repository at this point in the history
…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
zenspider committed May 2, 2012
1 parent 85f8f77 commit 6885810
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
32 changes: 16 additions & 16 deletions lib/minitest/unit.rb
Expand Up @@ -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

##
Expand Down Expand Up @@ -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)

Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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

##
Expand Down
13 changes: 11 additions & 2 deletions test/test_minitest_unit.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6885810

Please sign in to comment.