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

Viewed 3622

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?

2 Answers
Related