Rails feature testing with logged in user (undefined method 'session')

omniauth, rspec, ruby-on-rails, ruby-on-rails-3, session

Solution

The rack_session_access gem seems to work well: https://github.com/railsware/rack_session_access

With it, the test becomes:

require 'spec_helper'

describe "My page" do
  it "has what I want on it when logged in" do
    user = FactoryGirl.create(:user)
    page.set_rack_session(user: user.id)
    visit my_path
    page.should have_content "Foobar"
  end
end

Problem

I'm writing feature specs with rspec and want to skip the login step each time. Users are authenticated through omniauth (no devise) and a `session[:user]` variable is set and then referenced to stay logged in. I want to be able to set the session variable directly if possible: ``` require 'spec_helper' describe "My page" do it "has what I want on it when logged in" do user = FactoryGirl.create(:user) session[:user] = user.id visit my_path page.should have_content "Foobar" end end ``` but this gives ``` Failure/Error: session[:user] = user.id NameError: undefined local variable or method `session' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fd13456d170> ``` Is there any way to set the session variable directly so that I can avoid the login step in most of the tests?

Original source

Related problems