Testing devise with shoulda
Asked Answered
F

2

14

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

Fossil answered 15/5, 2010 at 7:42 Comment(0)
N
17

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
Nessus answered 15/5, 2010 at 17:41 Comment(0)
C
12

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?

Callida answered 29/5, 2010 at 0:37 Comment(3)
That's different. He was just putting "include Devise::TestHelpers" in the base scope of his test_helper.rb file, not scoped inside the TestCase class.Nessus
That is precisely what the README says to do.Talbot
+1 for "yes after the END of the class ActiveSupport::TestCase"Narcotize

© 2022 - 2024 — McMap. All rights reserved.