[rspec-users] Cookies - how to set in controller specs?

Christopher Bailey chris at cobaltedge.com
Tue Jul 1 19:37:03 EDT 2008

I've been searching Google, the mailing list, etc, etc. and can't for
the life of me get a cookie to be set in a controller spec.  From
everything I've read on the web, it appears all I need to do is the

  cookies[:name] = value


  cookies[:name] = { :value => something, :expires => 1.year.from_now }

I have also see things like doing "@request.cookies[:name]..." or
setting the value to doing CGI::Cookie.new(...), and so on.

I do not want to mock cookies, I want to actually test them, as that
is the logic I'm trying to test.  I know that my actual code works as
I've run through this by directly testing in the browser, but of
course I want specs to test it.  Can someone show a test of setting a
cookie, getting a page/action (and then optionally testing cookie
after that)?

Christopher Bailey
Cobalt Edge LLC

More information about the rspec-users mailing list