在Ruby on Rails Minitest中,有没有办法在ActionDispatch::IntegrationTest
测试中调用请求之前设置标题?
目前,before
/ setup
内部不是解决方案。
# Default way
test 'foo' do
get '/home', headers: { foo: "bar" }
end
# How I wish
test 'foo' do
@request.headers['foo'] = "bar"
get '/home'
end
# I already tried and it did not work...
test 'foo' do
request.headers['foo'] = 'bar'
@request.headers['foo'] = 'bar'
request.env['foo'] = 'bar'
@request.env['foo'] = 'bar'
request.env['HTTP_FOO'] = 'bar'
@request.env['HTTP_FOO'] = 'bar'
get '/home'
end
答案 0 :(得分:0)
默认方式是好的,但根据标题自定义标题的命名,你应该以" X开始 - "前缀。
test 'foo' do
get '/home', headers: { "X-Foo": "bar" }
end