[rspec-users] stub and should_receive

Phillip Koebbe phillipkoebbe at gmail.com
Tue Mar 2 14:38:08 EST 2010

Nevermind. If I would have waited five more minutes before clicking 
"Send", I would have seen my error.


Phillip Koebbe wrote:
> What is the expected behavior when a model has both stub and 
> should_receive defined for the same method?
> I have a helper method which creates an admin "logged in":
> def stub_user(is_administrator)
>     user = stub_model(User)
>     user.stub(:is_administrator).and_return(is_administrator)
>     User.stub(:find_by_id).and_return(user)
>     user
> end
> def setup_admin
>     @admin = stub_user(true)
>     session[:user_id] = @admin.id
> end
> In an admin controller spec, I have to setup_admin so the specs can 
> get to the controllers, but then later in particular contexts, I do
> @some_user = stub_model(User)
> User.should_receive(:find_by_id).and_return(@some_user)
> This is to simulate selecting a user from a list and either showing or 
> editing details. Based on what I'm seeing, it appears that the the 
> find_by_id return values are getting mixed up. Am I wrong to attempt 
> to use both of these or should this work as I expect? If the latter, 
> then I have more digging to do to determine what's going wrong.
> Thanks,
> Phillip 

More information about the rspec-users mailing list