在我的 rails 项目中,其中一个初始化程序请求并从S3
.
S3.buckets[CONFIG['aws']['cdn_bucket']].objects['object_name'].read
这打破了使用webmock
gem的 rspec 测试套件
WebMock.allow_net_connect!(:net_http_connect_on_start => true)
尝试运行测试套件时出现以下错误
WebMock::NetConnectNotAllowedError
You can stub this request with the following snippet:
stub_request(:get, "https://bucket.s3.amazonaws.com/object_name").with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'', 'Authorization'=>'AWS AKxxxxxx:Hyxxxxxxxxxx', 'Content-Type'=>'', 'Date'=>'Thu, 14 Apr 2016 15:10:18 GMT', 'User-Agent'=>'aws-sdk-ruby/1.60.2 ruby/1.8.7 i686-darwin15.3.0'}).to_return(:status => 200, :body => "", :headers => {})
添加此存根不会修复错误。事实上,添加以下任何内容似乎都不会做出任何改变:
WebMock.stub_request(:any, /.*amazonaws.*/).with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'', 'Authorization'=>'AWS AKIxxxxxxxxxx:MSxxxxxxxx'}).to_return(:status => 200, :body => "stubbed response", :headers => {})
WebMock.stub_request(:any, /.*amazonaws.*/).to_return(:status => 200, :body => "stubbed response", :headers => {})
我在这里想念什么?错误消息中的详细标头在这里似乎没有意义,以允许各种请求S3
编辑:
我只是注意到添加WebMock.disable!
到spec_helper
也不会导致任何变化。我没有将存根添加到正确的位置吗?如果不在,应该在哪里添加spec_helper
?