rubyrspecexpectations

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


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?


Solution

  • Use the anything matcher:

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