User login during testing with rspec and authlogic

I have a specification for testing a controller as shown below

require 'spec_helper'

describe ProductsController do
setup :activate_authlogic

describe "user not logged in" do

it "should not GET index" do
get :index
response.should redirect_to(login_path)
end

end

describe "user logged in" do

before(:each) do
UserSession.create :username => "rohit", :password => "test123"
end

it "should GET index" do
get :index
response.should redirect_to(products_path)
end

end

end

I also used this line in spec_helper.rb

require "authlogic/testcase"

The test for "user did not log in", but for "user logged in" failed

'ProductsController user is logged in should GET index' FAILED
expected redirect to "/products", got no redirect
+5
source share
1 answer

This seems normal because you are getting the '/ products' URL with a registered user. Then He sees this page. It is not redirected to the page that it sees.

Each test is independent. The state is not saved in the previous test.

-1
source

All Articles