问题
How do I set cookies in my request specs?
The solutions on the following page did not work:
Rspec: setting cookies in a helper test
Namely, request.cookies[:whatever] = 'something'
says that request
is a nil
object. I also tried helper.cookies[:whatever] = 'something'
, and that also did not work (helper
in that case was nil
).
回答1:
Try just the following:
cookies[:whatever] = 'something'
回答2:
Make sure you are using the rspec-rails gem and are requiring 'rspec/rails' in your spec_helper, not just 'rspec'.
来源:https://stackoverflow.com/questions/11962808/rails-rspec-how-to-set-cookies-in-a-request-spec