devise icon indicating copy to clipboard operation
devise copied to clipboard

ArgumentError: uncaught throw :warden

Open lporras opened this issue 14 years ago • 3 comments

I'm trying to test this:

class PagesController < ApplicationController
  before_filter :authenticate_user!

  def landing
  end
...
end
describe PagesController do
  include Devise::TestHelpers
...
  describe "GET#landing when no user sign in" do

    it "should redirect to users/sign_in" do
      get :landing
      response.should redirect_to new_user_session_path
    end

  end
end

but I'm getting this error:

ArgumentError: uncaught throw :warden

lporras avatar Dec 12 '11 18:12 lporras

Yeah, you need to sign in the user, as the TestHelpers docs say.

josevalim avatar Dec 12 '11 18:12 josevalim

As of Dec 17, 2011 the docs say:

Devise::TestHelpers provides a facility to test controllers in isolation when using ActionController::TestCase allowing you to quickly sign_in or sign_out a user. Do not use Devise::TestHelpers in integration tests.

Notice you should not test Warden specific behavior (like Warden callbacks) using Devise::TestHelpers since it is a stub of the actual behavior. Such callbacks should be tested in your integration suite instead.

This means that you can't test redirection for login in your functional tests. Use an integration test instead.

Note: "TestHelpers docs" that @josevalim refers to are located in the Devise::TestHelpers module, not the README. :) Some of us are dense.

epochwolf avatar Dec 17 '11 20:12 epochwolf

Thanks @epochwolf for your explain

lporras avatar Dec 18 '11 21:12 lporras