我正在尝试为我的控制器编写测试,该控制器接收来自外部服务的请求。到目前为止,这是我的测试:
describe ApplyController do
context 'when valid' do
let(:parameters) do
file = File.join File.dirname(__FILE__), '..', 'samples', 'Indeed.json'
JSON.parse(File.read file)
end
let(:signature) { 'GC02UVj0d4bqa5peNFHdPQAZ2BI=' }
subject(:response) { post :indeed, parameters, 'X-Indeed-Signature' => signature }
it 'returns 200 ok if Request is valid' do
expect(response.status).to eq 200
end
end
end
这应该根据文档 https://www.relishapp.com/rspec/rspec-rails/v/3-0/docs/controller-specs/cookies我可以find http://guides.rubyonrails.org/testing.html#setting-headers-and-cgi-variables.
我的控制器现在看起来像这样:
class ApplyController < Application Controller
def indeed
binding.pry
end
end
当我在测试中进入 Pry 并尝试检查request.headers['X-Indeed-Signature']
我总是只是得到nil
我有什么遗漏的吗?我正在使用 Rails 3.2 和 Rspec 3
我想你想要(直接从你的链接之一)
it "returns 200 ok"
@request.headers['X-Indeed-Signature'] = signature
post :indeed, parameters
response.status.should == 200
end
您不需要主题(:响应)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)