How to set request headers in rspec request spec?

前端 未结 10 1249
独厮守ぢ
独厮守ぢ 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:56

    I'm adding this here, as I got majorly stuck trying to do this in Rails 5.1.rc1

    The get method signature is slightly different now.

    You need to specify the options after the path as keyword arguments, i.e.

    get /some/path, headers: {'ACCEPT' => 'application/json'}

    FYI, the full set of keywords arguments are:

    params: {}, headers: {}, env: {}, xhr: false, as: :symbol

提交回复
热议问题