RSpec: Only stub a method when a particular argument is passed

To only stub a method call if a given argument is used, but use the default implementation for other arguments:

object.should_receive(:some_method).and_call_original
object.should_receive(:some_method).with('my argument').and_return('other value')

Requires rspec-mocks 2.13+.

Henning Koch Over 9 years ago