Rails/rspec: how to set cookies in a request spec?

时间秒杀一切 提交于 2020-01-14 07:18:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!