ruby-on-rails – 将标题附加到Rspec控制器测试

我正在为我的一个控制器写出测试,该控制器接收外部服务的请求.到目前为止,这是我的考验:
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

这应该按照documentation可以find工作.

我的控制器现在看起来像这样:

class ApplyController < Application Controller
  def indeed
    binding.pry
  end
end

当我在测试中进入Pry,并尝试检查request.headers的值[‘X-Indeed-Signature’]我总是没有

有没有我失踪的东西?我使用的是Rails 3.2和Rspec 3

解决方法

我想你想(直接从你的一个链接)
it "returns 200 ok"
  @request.headers['X-Indeed-Signature'] = signature
  post :indeed,parameters
  response.status.should == 200
end

你不需要主题(:回复)

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...