devise test integration problem

Created on 16 Feb 2012  路  6Comments  路  Source: heartcombo/devise

hi there I have a problem, I made a simple test integration

    require File.expand_path("../../helper/test_integration_helper", __FILE__)

    class AdvisorsTest < ActionDispatch::IntegrationTest
      setup do
        @user = Factory(:user)
        sign_in(@user)
       end

       test 'shows users' do
         visit "/users"
       end
    end

the problem is when the test has the class ActionDispatch::IntegrationTest the test throws

NoMethodError: undefined method `env' for nil:NilClass

but when I add the class

ActionController::TestCase, 

the test throws the same error but after add

class ActionController::TestCase
  include Devise::TestHelpers  
end

the test works ok, but I want to use integration class cause this is an integration test

anyone knows why is this?

Most helpful comment

ok for getting works this you have to prevent load devise helper cause this try to find @request and this is nil for capybara so you have to put in your test_helper

class ActionController::TestCase
  include Devise::TestHelpers
end

so this way just load devise helper for controllers, so now you can use ActionDispatch::IntegrationTest for you integrations test using this guide https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara

thanks!

All 6 comments

You can't use Devise::TestHelpers with integration testing. It is in the documentation, repeated many times here and in the mailing list. You need to sign in manually by filling up the form.

hi @josevalim I cant make sign in manually cause I'm using cas server (the db user is in another place)(https://github.com/nbudin/devise_cas_authenticatable) and this test works for me when the test class inherits from ActionController::TestCase, by the way devise has a guide for use it with caypara (https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara) as said before this way works fine if I use ActionController::TestCase I want to know why it doesnt works when inhertis from ActionDispatch::IntegrationTest

The guide you pointed in the wiki page uses Warden helpers, not Devise ones. Those ones would work fine with integration tests.

yeap with warden helpers works fine the problem that i have is the class from inhertis the test, do you know what is this?

even using warden helpers like says this guide I get

NoMethodError: undefined method `env' for nil:NilClass

if I'm using the class ActionDispatch::IntegrationTest

ok for getting works this you have to prevent load devise helper cause this try to find @request and this is nil for capybara so you have to put in your test_helper

class ActionController::TestCase
  include Devise::TestHelpers
end

so this way just load devise helper for controllers, so now you can use ActionDispatch::IntegrationTest for you integrations test using this guide https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara

thanks!

Was this page helpful?
0 / 5 - 0 ratings