| Class | NotAMock::Matchers::ArgsMatcher |
| In: |
lib/not_a_mock/matchers/args_matcher.rb
|
| Parent: | CallMatcher |
Matcher for
with(...)
Not A Mock supports the use of RSpec‘s patterns for argument matching in mocks, and extends them. The most useful are listed below.
The anything pattern will match any value. For example:
object.should have_received(:message).with(1, anything, 3)
will match the following calls:
object.message(1, 2, 3) object.message(1, 'Boo!', 3)
but not:
object.message(3, 2, 1) object.message(1, 2, 3, 4)
The in_any_order pattern will match an array argument, but won‘t care about order of elements in the array. For example:
object.should have_received(:message).with(in_any_order([3, 2, 1]))
will match the following calls:
object.message([3, 2, 1]) object.message([1, 2, 3])
but not:
object.message([1, 2, 3, 4])
# File lib/not_a_mock/matchers/args_matcher.rb, line 46
46: def initialize(args, parent = nil)
47: super parent
48: @args = args
49: end
# File lib/not_a_mock/matchers/args_matcher.rb, line 56
56: def failure_message_without_parents
57: if matched?
58: if @args.empty?
59: ", without args"
60: else
61: ", with args #{@args.inspect}"
62: end
63: else
64: if @args.empty?
65: ", but not without args"
66: else
67: ", but not with args #{@args.inspect}"
68: end
69: end
70: end