[英]Rails/rspec: how to set cookies in a request spec?
How do I set cookies in my request specs? 如何在我的请求规范中设置cookie?
The solutions on the following page did not work: 以下页面上的解决方案无效:
Rspec: setting cookies in a helper test Rspec:在帮助测试中设置cookie
Namely, request.cookies[:whatever] = 'something'
says that request
is a nil
object. 也就是说, request.cookies[:whatever] = 'something'
表示该request
是一个nil
对象。 I also tried helper.cookies[:whatever] = 'something'
, and that also did not work ( helper
in that case was nil
). 我也尝试过helper.cookies[:whatever] = 'something'
,这也没有用(在这种情况下helper
是nil
)。
尝试以下内容:
cookies[:whatever] = 'something'
确保您使用的是rspec-rails gem并且在spec_helper中需要'rspec / rails',而不仅仅是'rspec'。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.