Trouble with RSpec's with method
Posted
by Thiago
on Stack Overflow
See other posts from Stack Overflow
or by Thiago
Published on 2010-04-19T20:58:06Z
Indexed on
2010/04/20
2:13 UTC
Read the original article
Hit count: 358
Hi there,
I've coded the following spec:
it "should call user.invite_friend" do user = mock_model(User, :id => 1) other_user = mock_model(User, :id => 2) User.stub!(:find).with(user.id).and_return(user) User.stub!(:find).with(other_user.id).and_return(other_user) user.should_receive(:invite_friend).with(other_user) post :invite, { :id => other_user.id }, {:user_id => user.id} end
But I'm getting the following error when I run the specs
NoMethodError in 'UsersController POST invite should call user.invite_friend' undefined method `find' for # Class:0x86d6918 app/controllers/users_controller.rb:144:in `invite' ./spec/controllers/users_controller_spec.rb:13:
What's the mistake? Without .with it works just fine, but I want different return values for different arguments to the stub method. The following controller's actions might be relevant:
def invite me.invite_friend(User.find params[:id]) respond_to do |format| format.html { redirect_to user_path(params[:id]) } end end def me User.find(session[:user_id]) end
© Stack Overflow or respective owner