2

How to write correctly the expectation with matching first argument and ignoring other arguments? There can be any number of other arguments.

expect_any_instance_of(MyClass).to receive(:my_method).with('Argument', any_args)

I got this error:

RSpec::Mocks::MockExpectationError: #<MyClass:0x4589d604> received :my_method with unexpected arguments
  expected: ("Argument", any args)
       got: ("Argument", 0, 100, nil)

Why does it not matched the arguments?

Could you suggest a custom matcher for this?

mirelon
  • 4,896
  • 6
  • 40
  • 70
  • 1
    Probably any args works only, if you use it as single param. Like expect_any_instance_of(MyClass).to receive(:my_method).with(any_args) – Stanislav Mekhonoshin Dec 05 '14 at 15:07
  • 1
    Yep, it seems it started allowing it to be used for sublists in [3.2](https://relishapp.com/rspec/rspec-mocks/v/3-2/docs/setting-constraints/matching-arguments). – Halil Özgür Jul 14 '17 at 13:51

0 Answers0