如何在其中设置标题before each
像下面这样?
RSpec.describe "Users API", type: :request do
before :each do
host! "example.org"
// set a header for all requests here ??
end
end
可能重复:如何在 rspec 请求规范中设置请求标头? https://stackoverflow.com/questions/9654465/how-to-set-request-headers-in-rspec-request-spec
但上面没有回答我的问题。
找到了一个解决方案。包括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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)