ActionDispatch nil value for env[ENV_SESSION_OPTIONS_KEY]

338 views Asked by At

I'm trying to run a capybara cookie feature spec, and when I call the visit [URL] method the stack trace gives me the following error.

Failures:

  1) Cookie Configuration writes cookies
     Failure/Error: visit('/cookies')
     NoMethodError:
       undefined method `[]=' for nil:NilClass
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/request/session.rb:169:in `load!'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/request/session.rb:164:in `load_for_write!'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/request/session.rb:153:in `merge!'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/request/session.rb:13:in `create'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/session/abstract_store.rb:69:in `prepare_session'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.5.3/lib/rack/session/abstract/id.rb:224:in `context'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rack-1.5.3/lib/rack/session/abstract/id.rb:220:in `call'
     # /Users/amat/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/actionpack-4.0.13/lib/action_dispatch/middleware/cookies.rb:486:in `call'

Part of the problem I suspect is in actionpack-4.0.13/lib/action_dispatch/request/session.rb we have the code:

def self.find(env)
  env[ENV_SESSION_OPTIONS_KEY]
end

Which is returning nil since I guess env[ENV_SESSION_OPTIONS_KEY] isn't set. And because it returns nil, when it calls:

def load!
   id, session = @by.load_session @env
   options[:id] = id
   @delegate.replace(stringify_keys(session))
   @loaded = true
end

options[:id] gives the error seen in the stack trace above.

Is this something I manually will have to stub in the test? Is there a configuration I'm missing probably?

EDIT: In case you want to see the spec code, it is fairly straight forward:

require 'spec_helper'

describe 'Cookie Configuration', type: :feature do
  it 'writes cookies' do
    visit('/cookies')
    ..
  end
end
0

There are 0 answers