[rspec-users] Rspec - stubbing same class multiple times with different co

Tero Tilus
Wed, 23 Jul 2008 04:56:16 -0000

2008-07-23 04:37, Ry An:
> User.stub!(:find).with(1).and_return(@user)
> User.stub!(:find).with(2).and_return(@user2)
>
> the second call returns
> undefined local variable or method `find'' for
> #<Class:0x7faf42964d00>

This is a kludge, but you might be able to work around your situation
using

  User.stub!(:find).and_return { ... calculate retval ... }

or

  User.stub!(:find).and_return(@user, @user2)

see http://rspec.info/documentation/mocks/stubs.html

> Any ideas as to why this is not working? or better still how to get
> it working.

Uhh, no idea, sorry.

--
Tero Tilus ## 050 3635 235 ## http://www.tilus.net/koti/tero/