ArgumentError: uncaught throw :warden
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
Yeah, you need to sign in the user, as the TestHelpers docs say.
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.
Thanks @epochwolf for your explain