亚马逊S3上传测试仅在使用WebMock

时间:2017-02-10 05:25:25

标签: ruby-on-rails ruby aws-sdk circleci webmock

我有一个关于将图像上传到S3的测试,无论它在哪里测试,我都会发出请求。

所有测试都在本地传递,但在圆圈CI上我得到以下异常:

WebMock::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://169.254.169.254/latest/meta-data/iam/security-credentials/ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}

You can stub this request with the following snippet:

stub_request(:get, "http://169.254.169.254/latest/meta-data/iam/security-credentials/").
  with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
  to_return(:status => 200, :body => "", :headers => {})

1 个答案:

答案 0 :(得分:1)

这是因为我没有为CI上的AWS_ID和AWS_SECRET设置ENV变量