So I was just trying to call a log_in method from user controller in the RSpec as
it "should get the index page" do
@user = User.new({ :email => "employee@test.com" })
log_in(@user)
get 'index'
response.should be_success
end
The result I got is like
1) EmployeesController GET 'index' should get the index page
Failure/Error: log_in(user)
NoMethodError:
undefined method `log_in' for #<RSpec::Core::ExampleGroup::Nested_1:0x4ac0328>
# ./spec/controllers/employees_controller_spec.rb:11:in `user_log_in'
# ./spec/controllers/employees_controller_spec.rb:16:in `block (2 levels) in <top (required)>'
Can someone help me out? Thanks
Edited March 11th, 2011
Here is the log_in method which is in UserController
def log_in(user)
session[:current_user] = user.id
end
If you want to call a method on the controller in an RSpec controller test, you could use the following.
It should call the method. I dont know if this is really a best practice. A better method would be to stub the logged_in method as BurmajaM suggested.