Given the code
env "rack.session", {:var => 'value'}
I can set a session variable in rack-test. However, how can I (using rack-test) test for said session variable in RSpec? Hypothetically, for example:
expect(env['rack.session'][:var]).to eq('value')
I can't seem to find any documentation for reading Rack environment variables, only writing them.
Just use the session method on the last request:
last_request.session
This will give you the session hash. A Sample:
it 'allows to access the session' do
get '/'
session = last_request.session
expect(session).to be_a Hash
expect(session[:var]).to eq 'value'
end
I've tested with rack v1.6.5 and rack-test v0.6.3 but it should work as well with rack version 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With