How to set request headers in rspec request spec?

前端 未结 10 1248
独厮守ぢ
独厮守ぢ 2020-12-04 08:33

In the controller spec, I can set http accept header like this:

request.accept = \"application/json\"

but in the request spec, \"request\"

10条回答
  •  臣服心动
    2020-12-04 08:51

    You should be able to specify HTTP headers as the third argument to your get() method as described here:

    http://api.rubyonrails.org/classes/ActionDispatch/Integration/RequestHelpers.html#method-i-get

    and here

    http://api.rubyonrails.org/classes/ActionDispatch/Integration/Session.html#method-i-process

    So, you can try something like this:

    get '/my/path', nil, {'HTTP_ACCEPT' => "application/json"}
    

提交回复
热议问题