Skip to content

Commit fed3387

Browse files
committed
Add custom matcher example to Expectatation#with docs
1 parent 17a4856 commit fed3387

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/mocha/expectation.rb

+16
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ def at_most_once
271271
# object.expects(:expected_method).with() { |value| value % 4 == 0 }
272272
# object.expected_method(17)
273273
# # => verify fails
274+
#
275+
# @example Extracting a custom matcher into an instance method on the test class.
276+
# class MyTest < Minitest::Test
277+
# def test_expected_method_is_called_with_a_value_divisible_by_4
278+
# object = mock()
279+
# object.expects(:expected_method).with(&method(:divisible_by_4))
280+
# object.expected_method(16)
281+
# # => verify succeeds
282+
# end
283+
#
284+
# private
285+
#
286+
# def divisible_by_4(value)
287+
# value % 4 == 0
288+
# end
289+
# end
274290
def with(*expected_parameters_or_matchers, &matching_block)
275291
@parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
276292
self

0 commit comments

Comments
 (0)