How to expect some (but not all) arguments with RSpec should_receive?

B Seven picture B Seven · Oct 7, 2013 · Viewed 24k times · Source
class Foo
  def bar(a, b)
  ...

Foo.should_receive( :bar )

expects bar to be called with any arguments.

Foo.should_receive( :bar ).with( :baz, :qux )

expects :baz and :qux to be passed in as the params.

How to expect the first param to equal :baz, and not care about the other params?

Answer

Dylan Markow picture Dylan Markow · Oct 7, 2013

Use the anything matcher:

Foo.should_receive(:bar).with(:baz, anything)