Class NotAMock::Matchers::ArgsMatcher
In: lib/not_a_mock/matchers/args_matcher.rb
Parent: CallMatcher

Matcher for

 with(...)

Argument Matchers

Not A Mock supports the use of RSpec‘s patterns for argument matching in mocks, and extends them. The most useful are listed below.

Anything Matcher

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)

In Any Order Matcher

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])

Methods

Public Class methods

[Source]

    # 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

Public Instance methods

[Source]

    # 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

[Source]

    # File lib/not_a_mock/matchers/args_matcher.rb, line 51
51:       def matches_without_parents?
52:         @calls = @parent.calls.select {|entry| @args == entry[:args] }
53:         !@calls.empty?
54:       end

[Validate]