RSpec Request - How to set http authorization header for all requests

后端 未结 4 2177
清歌不尽
清歌不尽 2021-02-07 06:01

I\'m using rspec request to test a JSON API that requires an api-key in the header of each request.

I know I can do this:

get \"/v1/users/janedoe.json\"         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-02-07 06:25

    I know that this question has already been answered but here's my take on it. Something which worked for me:

    request.headers['Authorization'] = token
    

    instead of:

    request.env['Authorization'] = token
    

提交回复
热议问题