使用shoulda测试设备
我在使用 shoulda 测试设备时遇到一些困难:
2) Error:
test: handle :index logged as admin should redirect to Daily page.
(Admin::DailyClosesControllerTest):
NoMethodError: undefined method `env' for nil:NilClass
devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in
`setup_controller_for_warden'
我的 test_helper 中有这个:
include Devise::TestHelpers
想法? 提前致谢,
克里斯蒂
I'm having some difficulties in testing devise with shoulda:
2) Error:
test: handle :index logged as admin should redirect to Daily page.
(Admin::DailyClosesControllerTest):
NoMethodError: undefined method `env' for nil:NilClass
devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in
`setup_controller_for_warden'
I have this in my test_helper:
include Devise::TestHelpers
Thoughts ?
Thanks in advance,
Cristi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
include Devise::TestHelpers
不会进入 test_helper.rb 文件,而是在各个测试类的范围内。就像他们的自述文件所示:include Devise::TestHelpers
doesn't go in the test_helper.rb file, but rather inside the scope of the individual testing classes. Just like their README shows:我不确定 rspeicher 是否完全正确,但是将:放在
test_helper.rb 的最底部(是的,在
class ActiveSupport::TestCase
的END
之后)应该工作。到目前为止,它已经用于我的 3 或 4 个项目,包括我今天正在做的一个。如果您在测试中使用固定装置,则可以使用
sign_in users(:one)
。除非应该把事情搞砸了?I'm not sure if rspeicher is fully correct, but putting:
at the very bottom of test_helper.rb (yes after the
END
of theclass ActiveSupport::TestCase
) should work. It has for 3 or 4 projects of mine so far, including one i'm working on today.You then can use
sign_in users(:one)
if you are using fixtures, in your tests. Unless shoulda is messing it up?