如何在before each
中设置标题,如下所示?
RSpec.describe "Users API", type: :request do
before :each do
host! "example.org"
// set a header for all requests here ??
end
end
可能重复:How to set request headers in rspec request spec?
但上面没有回答我的问题。
答案 0 :(得分:0)
找到一个解决方案。包含Rack::Test::Methods
模块。
我不知道为什么请求规范不提供此功能。
RSpec.describe "Users API", type: :request do
include Rack::Test::Methods
before :each do
host! "example.org"
// now we can do
header 'Authorization', "Bearer #{some_token}"
end
end