Ry An
2008-Jul-23 02:37 UTC
[rspec-users] Rspec - stubbing same class multiple times with different co
Im having a hard time with a rspec controller test im writting, I need to stub! the User.find call twice once to return the owning user and once to return the viewing user. however when I attempt 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> I''ve managed to replicate the behavior outside of this specific test and I know the code works as I can test it manually. Any ideas as to why this is not working? or better still how to get it working. Thanks for the help in advance -- Posted via http://www.ruby-forum.com/.
Lori M Olson
2008-Jul-23 04:06 UTC
[rspec-users] Rspec - stubbing same class multiple times with different co
Have you tried using should_receive instead of stub! ? Sent from my iPhone On 22-Jul-08, at 8:37 PM, Ry An <lists at ruby-forum.com> wrote:> Im having a hard time with a rspec controller test im writting, I need > to stub! the User.find call twice once to return the owning user and > once to return the viewing user. however when I attempt > > 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> > > I''ve managed to replicate the behavior outside of this specific test > and > I know the code works as I can test it manually. > > Any ideas as to why this is not working? or better still how to get it > working. > > Thanks for the help in advance > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Tero Tilus
2008-Jul-23 04:56 UTC
[rspec-users] Rspec - stubbing same class multiple times with different co
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/
David Chelimsky
2008-Jul-23 05:18 UTC
[rspec-users] Rspec - stubbing same class multiple times with different co
On Tue, Jul 22, 2008 at 9:37 PM, Ry An <lists at ruby-forum.com> wrote:> Im having a hard time with a rspec controller test im writting, I need > to stub! the User.find call twice once to return the owning user and > once to return the viewing user. however when I attempt > > 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> > > I''ve managed to replicate the behavior outside of this specific test and > I know the code works as I can test it manually. > > Any ideas as to why this is not working?Not without more context. What you seem to be trying to do should work. Would please post the code of the spec (including any before blocks) and the code for the action in question? Thanks, David> or better still how to get it > working. > > Thanks for the help in advance > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >