How to stub Restul-authentication's current_user method?
Posted
by Thiago
on Stack Overflow
See other posts from Stack Overflow
or by Thiago
Published on 2010-05-12T18:51:19Z
Indexed on
2010/05/12
18:54 UTC
Read the original article
Hit count: 187
rspec
|ruby-on-rails
Hi there,
I'm trying to run the following spec:
describe UsersController, "GET friends" do
it "should call current_user.friends" do
user = mock_model(User)
user.should_receive(:friends)
UsersController.stub!(:current_user).and_return(user)
get :friends
end
end
My controller looks like this
def friends
@friends = current_user.friends
respond_to do |format|
format.html
end
end
The problem is that I cannot stub the current_user method, as when I run the test, I get:
Spec::Mocks::MockExpectationError in 'UsersController GET friends should call current
_user.friends'
Mock "User_1001" expected :friends with (any args) once, but received it 0 times[0m
./spec/controllers/users_controller_spec.rb:44:
current_user is a method from Restful-authentication, which is included in this controller. How am I supposed to test this controller?
Thanks in advance
© Stack Overflow or respective owner