Search code examples
ruby-on-railsrspecdeviserspec-rails

How can I test a controller method that uses information from the current_user of Devise?


I am trying to test a controller method that obtains the user_id from the current_user of devise.

Following other answered questions, I try to sign_in with the User mock_up but it gives me the same problem as in undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x1057fd428> error while trying to set up RSpec with Devise. In that question, the accepted answer says that you can't use Devise helpers inside an rspec integration test.

Being this true, how can I test a controller method that needs a logged user to execute?


Solution

  • Why don't you Mock the "current_user"? Since its from Devise, its already been tested... You should have no coverage problems mocking it with your User under test