Skip to content

Commit

Permalink
+ assert_match now returns the MatchData on success. (Nakilon)
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//src/minitest/dev/": change = 13421]
  • Loading branch information
zenspider committed Jun 5, 2022
1 parent 8a131bf commit ed224bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/minitest/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def assert_match matcher, obj, msg = nil
assert_respond_to matcher, :"=~"
matcher = Regexp.new Regexp.escape matcher if String === matcher
assert matcher =~ obj, msg

Regexp.last_match
end

##
Expand Down
5 changes: 4 additions & 1 deletion test/minitest/test_minitest_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ def test_assert_kind_of_triggered

def test_assert_match
@assertion_count = 2
@tc.assert_match(/\w+/, "blah blah blah")
m = @tc.assert_match(/\w+/, "blah blah blah")

assert_kind_of MatchData, m
assert_equal "blah", m[0]
end

def test_assert_match_matchee_to_str
Expand Down
2 changes: 1 addition & 1 deletion test/minitest/test_minitest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def assert_success spec
it "needs to verify regexp matches" do
@assertion_count += 3 # must_match is 2 assertions

assert_success _("blah").must_match(/\w+/)
assert_kind_of MatchData, _("blah").must_match(/\w+/)

assert_triggered "Expected /\\d+/ to match \"blah\"." do
_("blah").must_match(/\d+/)
Expand Down

0 comments on commit ed224bc

Please sign in to comment.