Skip to content

Commit

Permalink
Add custom matcher example to Expectatation#with docs
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Dec 8, 2024
1 parent 17a4856 commit fed3387
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/mocha/expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ def at_most_once
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
# object.expected_method(17)
# # => verify fails
#
# @example Extracting a custom matcher into an instance method on the test class.
# class MyTest < Minitest::Test
# def test_expected_method_is_called_with_a_value_divisible_by_4
# object = mock()
# object.expects(:expected_method).with(&method(:divisible_by_4))
# object.expected_method(16)
# # => verify succeeds
# end
#
# private
#
# def divisible_by_4(value)
# value % 4 == 0
# end
# end
def with(*expected_parameters_or_matchers, &matching_block)
@parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
self
Expand Down

0 comments on commit fed3387

Please sign in to comment.