I have an rspec test that posts to an action. In the action, a session variable is definitely set, however in my controller test, the session hash is empty. How do I check in an Rspec test to see if the controller set the session variable to the right value?
You can access session directly in rspec like this: session[:key]
. Just compare that with the value you want.
See this. The main problem is that the variable session
is not accessible from the test code. To solve it, add the fowling lines at spec/spec_helper.rb
:
def session
last_request.env['rack.session']
end
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