You can clone with
HTTPS or Subversion.
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?
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?
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?
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).
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)
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
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
and then follows the guide
thanks for all