# Rspec - stubbing same class multiple times with different conditions

**URL:** <https://www.ruby-forum.com/t/rspec-stubbing-same-class-multiple-times-with-different-conditions/143074>\
**Category:** RSpec\
**Created:** [July 15, 2008, 12:05am UTC](https://www.ruby-forum.com/t/rspec-stubbing-same-class-multiple-times-with-different-conditions/143074 "2008-07-15T00:05:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tafkamk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90ced4/32.png) [@tafkamk](https://www.ruby-forum.com/u/tafkamk)\
**Post date:** [July 15, 2008, 12:05am UTC](https://www.ruby-forum.com/t/rspec-stubbing-same-class-multiple-times-with-different-conditions/143074/1 "2008-07-15T00:05:30Z")

</div>

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

View this message in context:  
[http://www.nabble.com/Rspec---stubbing-same-class-multiple-times-with-different-conditions-tp18446600p18446600.html](http://www.nabble.com/Rspec---stubbing-same-class-multiple-times-with-different-conditions-tp18446600p18446600.html)  
Sent from the rspec-users mailing list archive at [Nabble.com](http://Nabble.com).
