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

Posted . Visible to the public.

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+.

Profile picture of Henning Koch
Henning Koch
Last edit
Henning Koch
Keywords
stub, once
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2015-01-29 09:38)