Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

problem with integration tests #36

chebyte opened this Issue Feb 16, 2012 · 6 comments


None yet
2 participants

chebyte commented Feb 16, 2012

hi there, I have a question, I using CAS and I want to make integration test with capybara and test units, the problem is how can I do the login with capybara, I'm trying to stubs the login I dont need make a real login so I was seeing here


but I get

NoMethodError: undefined method `env' for nil:NilClass

I set the env to like this:

@request.env["devise.mapping"] = Devise.mappings[:user]

but returns the same error

so anyone knows what is the way for test this app with capybara through cas?



nbudin commented Feb 16, 2012

What the NoMethodError is telling you is that in the context of that statement, @request is nil. Where in your code did you put this statement?

chebyte commented Feb 16, 2012

this is my test_integration_helper


and this is my test


I tried with sign_in helper from devise and login_as helper from warden, I get the same error, nil env

do you see something wrong?


nbudin commented Feb 16, 2012

It looks like ActionDispatch::IntegrationTest doesn't have a @request object. (See https://github.com/rails/rails/blob/3de95fd9303ea2a2ffa5184f8cf32db63cb7f4ac/actionpack/lib/action_dispatch/testing/integration.rb for the source code.)

What it does have is a Session object as well as a method_missing? that delegates just about everything you do to that object. So you might be able to just do env["devise.mapping"] instead of @request.env["devise.mapping"], if the session exposes a env method (which I'm finding hard to tell just from the source code).

chebyte commented Feb 16, 2012

yeap seems that @request is nil, but in the devise code it is waiting for @request object, see this code is from devise, where the error happens

 def setup_controller_for_warden #:nodoc:
   @request.env['action_controller.instance'] = @controller

is wierd, I tried puts @request into the test but I get nil too, maybe this class ActionDispatch::IntegrationTest not set this one?

I could stubs the login on devise and test the app with capybara even if I'm using cas?, I cant make real login cause the db login is in another app (the cas server)


nbudin commented Feb 16, 2012

Ah, makes sense.

What I actually do in my apps is somewhat more complicated. I use a little embedded CAS server called castronaut (my fork is here), which I run alongside the app using ShamRack. That way, devise_cas_authenticatable is making actual CAS calls to a real CAS server (that is running locally).

For an example, see here: https://github.com/nbudin/vellum/blob/master/features/support/cas.rb

chebyte commented Feb 16, 2012

looks very good, but I found the solution, the problem was that devise not supports integration test so I was loading devise helper on test_helper so it load these for all test, this is bad cause request is nil for capybara, for capybara you just need use warden helper like this guide says (https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara), so you just need load devise like this

class ActionController::TestCase
  include Devise::TestHelpers

and then follows the guide

thanks for all


@chebyte chebyte closed this Feb 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment