I'm looking to test "get" request, controller action via RSPec, with a special header value. I have looked on Stackoverflow & nothing I have tried works. It never actually changes the header.
Here is what I have:
RSpec.describe IftttController, type: :controller do
context '/v1/status works with proper code' do
before :each do
request.headers.merge!({ 'IFTTT-Channel-Key' => ENV['IFTTT_CODE'] })
get :status
end
it 'return status code 200' do
expect(response.code).to eq('200')
expect(response).to have_http_status(:ok)
end
end
end
The headers never actually show up in my controller:
{"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-Download-Options"=>"noopen", "X-Permitted-Cross-Domain-Policies"=>"none", "Referrer-Policy"=>"strict-origin-when-cross-origin"}
Before you point me to the docs or other StackOverflow questions, I have tried:
This: https://relishapp.com/rspec-staging/rspec-rails/docs/controller-specs/setting-request-headers
This: How to set request headers in rspec request spec?
This: https://gist.github.com/quadrolls/9203f924f934398f6992162bbbcb1a0c
Nothing seems to actually pass the headers to the controller, whether I use type: :request
or type: :controller
or anything else that I try.
question from:
https://stackoverflow.com/questions/65931176/rspec-get-controller-action-with-headers 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…