Testing cookies - integration tests


I’m trying to test some cookie code with some integration tests, but I’m
not sure if this is possible.

Currently I’m creating a session (using open_session) running some code
that sets my cookie and this works fine, the cookie is being set. Now
cookies are supposed to exist across different sessions, so I try to
create a new session (again with open_session), but the cookie value no
longer exists. My code does work if I’m not testing with the test
framework, but I wasn’t sure if testing cookies is supported via
integration tests or not. Anybody have any idea if it is supported and
what I may be doing wrong?

Here’s basically what I’m trying to test…

start a new session and login (sets a cookie value)

open_session do |sess|
sess.extend SessionMethods
sess.login_user :remember => true
sess.get url_for(:controller => ‘main’)
sess.assert_equal sess.assigns(:user).id.to_s,

# start a new session, cookie should still be set
open_session do |sess|
  sess.extend SessionMethods
  sess.get url_for(:controller => 'main')

  ### cookies are empty!!!
  sess.assert !sess.assigns(:cookies)[:login].empty?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs