RSpec / Capybara Request Specification - Cannot Get Devise For New POST User Session

I am trying to start a new user session by creating an assistant that POSTs a new user session. That's what i

def login(user)
  post user_session_path, :login => user.username, :password => user.password
end

And for the user

user = Factory.create(:user)

I have a test in RSpec that directs the user to a page that requires authentication. Using the helper, I expect a new user session to be created. However, by launching the spec, he tells me that the current page is the login screen. This means that a new user session is not created, and the user is redirected to the login screen when accessing a limited resource without a user session. If you look at the test logs, it is.

Also looking at the logs, he says that the POST action is unauthorized.

Started POST "/login" for 127.0.0.1 at 2012-02-04 13:34:59 -0800
Processing by SessionsController#create as HTML
Parameters: {"login"=>"foo12", "password"=>"[FILTERED]"}
Completed 401 Unauthorized in 1ms
Processing by SessionsController#new as HTML
Parameters: {"login"=>"foo12", "password"=>"[FILTERED]"}
Rendered devise/shared/_links.erb (1.4ms)
Completed 200 OK in 15ms (Views: 12.7ms | ActiveRecord: 0.0ms)

, , . Capybara, , . .

+5
1

, Warden:: Test:: Helpers ( )

require 'spec_helper'
include Warden::Test::Helpers

describe "...Whatever..." do

  before(:each) do
    @user = Factory.create(:user)
    login_as @user, :scope => :user
  end
  ...

: http://blog.joshmcarthur.com/2011/06/11/integration-tests-with-devise-and-rspec/

+27

All Articles