1

I'm having issues now that i've added devise to my web app, theres a few SO questions on this but they just all point to a readme file and don't actually provide any fixes. I've had to include devise helpers as shown below in order to remove an issue saying the authentication method didn't exist

class ActiveSupport::TestCase
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
 fixtures :all

      # Add more helper methods to be used by all tests here...
  include Devise::TestHelpers
end

If i don't include it i end up with a huge amount of authentication errors:

ActionView::Template::Error: undefined method `authenticate' for nil:NilClass

but if it is included

 NoMethodError: undefined method `env' for nil:NilClass

Simply occurs in different places instead, is there an actual fix?

Example

ContactMailerTest#test_should_return_contact_email:
NoMethodError: undefined method `env' for nil:NilClass

Method:

test "should return contact email" do
mail = ContactMailer.contact_email("Email@Email.com", "Example",
                                   "SomeExample", @comment = "Hello")
assert_equal ['info@mynotes.com'], mail.to
assert_equal ['info@mynotes.com'], mail.from
end

This appears to be an issue with "Apparently there are issues with Devise::TestHelpers and integration testing" i am wondering if there is any known fix

Thanks!

kxdan
  • 187
  • 1
  • 15
  • I've simply got 3 models, one of which is a devise user model, and tests such as checking the GET commands work on web pages, the GET tests will fail as a result of including devise in the bundle – kxdan Nov 30 '15 at 16:58
  • Show the code, the error is certainly in your code. – Jaffa Nov 30 '15 at 17:00
  • check you have test environment setup in your application database or not? also where you are getting NoMethodError: undefined method `env' for nil:NilClass?? – Arvind Nov 30 '15 at 17:37
  • not sure but looking duplicate http://stackoverflow.com/questions/27284657/undefined-method-env-for-nilnilclass-in-setup-controller-for-warden-error – Arvind Nov 30 '15 at 17:42
  • I've stated about that other SO articles don't answer the question, The tests have always worked before i added the devise gem, its only the mailer and the audits model playing up, the others seem to function fine – kxdan Nov 30 '15 at 17:44
  • @kxdan show us where you have define mailer for test environment? – Arvind Nov 30 '15 at 18:30
  • I'm not sure i understand the question @Arv – kxdan Nov 30 '15 at 18:39

0 Answers0