我正在尝试使用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也有类似的问题.