简体   繁体   English

如何测试使用来自Devise的current_user的信息的控制器方法?

[英]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. 我正在尝试测试从devise的current_user获取user_id的控制器方法。

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 . 在其他已回答的问题之后,我尝试使用User mock_up登录,但是它给我带来了与#<RSpec :: Core :: ExampleGroup :: Nested_1 :: Nested_1:0x1057fd428>错误的未定义方法`sign_in'相同的问题用Devise设置RSpec In that question, the accepted answer says that you can't use Devise helpers inside an rspec integration test. 在该问题中,被接受的答案表明您不能在rspec集成测试中使用Devise帮助器。

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"? 为什么不嘲笑“ current_user”? Since its from Devise, its already been tested... You should have no coverage problems mocking it with your User under test 自Devise以来,它已经过测试...与被测用户嘲笑它应该没有覆盖问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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