How to test Sinatra application wich is using session?
get "/", {}, {'rack.session' => { 'foo' => 'blah' } }
This code doesn't work for me, I have 'enable :sessions' in my app.
How to test Sinatra application wich is using session?
get "/", {}, {'rack.session' => { 'foo' => 'blah' } }
This code doesn't work for me, I have 'enable :sessions' in my app.
It looks like the problem is actually to have
enable :sessions
activated.You have to deactivate this setting in order to be available to overwrite the session.
The solution could be:
In the other hand to be able to check any session change that the action is expected to do we can send not a hash to the rack.session but a pointer to a hash so we can check after the action call if the hash has changed:
I finally figured it out by monkey patching
Rack::Test::Session
:https://gist.github.com/troelskn/5047135
Just ran into this problem and the solution is simply the order of requiring the files, so @fguillen was correct. At the top of your spec, make sure you require rack/test before your sinatra app, so at a minimum, this should get you started:
Like Philip suggested, it would work better to manually set the session variable before the get request.