This solution is out of date, at least for Rails 3.2 and possibly 3.1. Instead give the gist here a shot, which is a better encapsulated solution anyway.
Ran into a simple problem today while I was speccing a new controller in our project. We generate some signed cookies for devices which check into our system and then we use those cookies to identify these devices when they return. Unfortunately the ActionController.TestRequest @request instance variable you get when using rspec-rails has the cookies collection as a basic hash and no cookies= method defined. This means that attempting to invoke permanent or signed on a hash results in a runtime error and you can't just assign the cookies collection to a valid ActionDispatch::Cookies::CookieJar instance.

You can get around this by going around the missing attribute setter and changing the instance variable directly.

#./specs/controllers/some_controller_spec.rb  
   # a new device is created here...
   ⋮
   @request.instance_variable_set(:@cookies, ActionDispatch::Cookies::CookieJar.build(@request))
   # the token is what we use to identify the device on subsequent requests
   # so our specs need to be able to create it when necessary
   @request.cookies.permanent.signed[:token] = [device.device_id, device.secret]
   ⋮
   # remainder of spec omitted

If you're doing stuff with the regular cookies hash you will need to merge! your cookies hash with the @request.cookies hash before building and assigning the full blown ActionDispatch::Cookies::CookieJar instance.

Reference: How to test cookies.permanent.signed in Rails 3