简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM