Skip to content

Commit

Permalink
Indicate when matcher logic is defined by block
Browse files Browse the repository at this point in the history
Previously the output from a test where such an exception was not
matched was a bit confusing, because no expected parameters were
displayed. While we can't easily display the logic from the block
itself, we can at least highlight that such logic does exist.

While this will change the content of some test failure messages, I have
previously specified that is not part of the documented API. [1]

[1]: #577
  • Loading branch information
floehopper committed Dec 8, 2024
1 parent fed3387 commit b30e443
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/mocha/parameters_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ def parameters_match?(actual_parameters)
end

def mocha_inspect
signature = matchers.mocha_inspect
signature = signature.gsub(/^\[|\]$/, '')
"(#{signature})"
if @matching_block
'(arguments_accepted_by_custom_matching_block)'
else
signature = matchers.mocha_inspect
signature = signature.gsub(/^\[|\]$/, '')
"(#{signature})"
end
end

def matchers
Expand Down
5 changes: 5 additions & 0 deletions test/unit/parameters_matcher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@ def test_should_indicate_that_matcher_will_match_any_actual_parameters
parameters_matcher = ParametersMatcher.new
assert_equal '(any_parameters)', parameters_matcher.mocha_inspect
end

def test_should_indicate_that_matcher_logic_is_defined_by_custom_block
parameters_matcher = ParametersMatcher.new { true }
assert_equal '(arguments_accepted_by_custom_matching_block)', parameters_matcher.mocha_inspect
end
end

0 comments on commit b30e443

Please sign in to comment.