[rspec-users] stub actions that depend on the parameter

Scott Taylor mailing_lists at railsnewbie.com
Mon Oct 8 15:35:18 EDT 2007


On Oct 8, 2007, at 2:23 PM, David Chelimsky wrote:

> On 10/8/07, Borja Martín <borjam at dagi3d.net> wrote:
>>
>> David Chelimsky escribió:
>>> On 10/8/07, Borja Martín <borjam at dagi3d.net> wrote:
>>>
>>>> Hi,
>>>> I'm pretty new to all related to bdd and rspec and I have the  
>>>> following
>>>> question. Is it possible to stub actions that return different  
>>>> objects
>>>> depending on the parameteres they were called with?Something  
>>>> like this:
>>>>
>>>> MyClass.stub!(:method).with(1).and_return(@mock_object_1)
>>>> MyClass.stub!(:method).with(2).and_return(@mock_object_2)
>>>>
>>>
>>> What happened when you tried this?
>>>
>>>
>> I become an error like this:
>> ...
>> undefined method `with' for #<Spec::Mocks::MethodStub:0xb6f20858>
>
> OK - that makes sense - you're probably using the latest release
> rather than the trunk. The trunk has been modified to support what
> you're trying to do.

What is the syntax for that?

Scott



More information about the rspec-users mailing list