rspec – 在请求规范中传递cookie

我正在尝试使用rspec 2和rails 3在执行GET请求时传递cookie.

到目前为止我已经尝试了以下内容.

get "/",{},{"Cookie" => "uuid=10"} # cookies[:uuid] is nil
request.cookies[:uuid] = 10 # request is nil
@request.env["Cookie"] = "uuid=10" # @request is nil
helper.request.cookies[:uuid] # helper is not defined
cookies[:uuid] = 10 # cookies[:uuid] is nil
controller.cookies[:uuid] = 10 # cookies is nil

可能吗?

解决方法

我有类似的问题,我没有找到适当的解决方案.

rspec-rails docs表明它应该是可能的:

# spec
request.cookies['foo'] = 'bar'
get :some_action
response.cookies['foo'].should eq('modified bar')

在执行get之前,我的spec请求总是为nil.

我现在正在嘲笑饼干:

before { Actiondispatch::Request.any_instance.stubs(cookies: {locale: :en}) }

this guy也有类似的问题.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 <div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些