无法存取虚假braintree的外部请求

时间:2014-11-21 20:06:08

标签: ruby-on-rails ruby braintree webmock

我有一个控制器测试,其中我正在测试一个方法,该方法也尝试使用braintree处理付款。我尝试将假braintree添加到项目中,但是当我运行测试时我被webmock告知我需要存根这个请求:

Real HTTP connections are disabled. Unregistered request: GET http://127.0.0.1:57793/__identify__ with headers {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'} (WebMock::NetConnectNotAllowedError)

You can stub this request with the following snippet:

stub_request(:get, "http://127.0.0.1:57793/__identify__").
  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 => {})

由于端口号不同,我在stub_request中使用正则表达式作为url参数:

  stub_request(:get, /http:\/\/127\.0\.0\.1:\d{5}\/__identify__/)
  .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 => {})

不幸的是,当我运行测试时,我仍然从webmock收到消息,说我需要存根请求。

0 个答案:

没有答案