Forum: RSpec stub and should_receive

Posted by Phillip Koebbe (pkoebbe)
on 2010-03-02 20:43
(Received via mailing list)
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
Posted by Phillip Koebbe (pkoebbe)
on 2010-03-02 20:46
(Received via mailing list)
Nevermind. If I would have waited five more minutes before clicking
"Send", I would have seen my error.

Blech.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.