views:

64

answers:

2

This is a pure syntactical question. I'm very new to RSpec.

I basically want to write something on the lines of this erroring line :

controller.stub!(:current_user(:update_attributes => false))

Anyone know how to properly write that?

RSpec's default looks like this :

User.stub(:find) { mock_user(:update_attributes => false) }
+2  A: 

This looks like a case for stub_chain:

controller.stub_chain(:current_user,:update_attributes).and_return(false)

Note that this is just going to replace methods in the list in the order they occur, so for this to make sense you'll have a current_user.update_attributes in your controller. If you have something like @user.update_attributes, I don't think it will work.

More info on APIDock

zetetic
Yours works too! Stub_chaining is amazing! :D Where would I be without Zetetic? Probably working at a McDonalds
Trip
lol! -- you're killin' me here :)
zetetic
A: 

I just blindly played around with a thousand variations and finally got it to pass with this :

controller.stub!(:current_user).and_return(@user)
@user.stub!(:update_attributes => false)

But seriously, does that even make any sense? It's passing :D

Trip