Testing devise with shoulda

為{幸葍}努か 提交于 2019-12-22 01:55:49

问题


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


回答1:


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:

class ActionController::TestCase
  include Devise::TestHelpers
end



回答2:


I'm not sure if rspeicher is fully correct, but putting:

class ActionController::TestCase
  include Devise::TestHelpers
end

at the very bottom of test_helper.rb (yes after the END of the class 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?



来源:https://stackoverflow.com/questions/2839328/testing-devise-with-shoulda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!