[rspec-users] Telling rspec that a method might be called with a OR b ... ?
rick.denatale at gmail.com
Tue Jul 28 17:38:32 EDT 2009
On Tue, Jul 28, 2009 at 4:57 PM, David Chelimsky<dchelimsky at gmail.com> wrote:
>> for arguments. Any way to tell rspec that a method might be called
>> with argument A or B (or C) ? :)
> There is no way to specify A or B, but you can stub both and set
> expectations about the resulting behavior that tie back to the stub
> values you set up. For example:
> @thing = stub_model(Thing)
> If you do that in a before(:each) block, now the implementation can
> use any of those methods and set expectations like
> assigns[:thing].should == @thing, etc. This effectively does what you
> are doing, but not in the most explicit way.
I think though that the OP want's to set a message expectation with
variation on the arguments, NOT which message.
@some_object.should_receive(:some_message).with(any_of(a, b, c))
As long as you don't need to set different return values for different
arguments, that could be done with a new ArgumentMatcher.
More information about the rspec-users