1

I have a controller test in which I'm testing a method that also tries to process a payment with braintree. I tried adding fake braintree to the project, but when I run the test I'm told by webmock that I need to stub this request:

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 => {})

Since the port number varies, I'm using a regex for the url parameter in stub_request:

  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 => {})

Unfortunately, when I run the test I still get the message from webmock saying I need to stub the request.

xxyyxx
  • 2,306
  • 3
  • 24
  • 34
  • What is port 57793? Can you run a `sudo netstat -anp | grep 57793` to see what process, if any, is listening on that port? – Jared Beck Nov 21 '14 at 20:38
  • It looks like the request is not stubbed at the time when request is made. If the request was stubbed, you would see the list of currently registered stubs as part of the error message. – Bartosz Blimke Nov 22 '14 at 12:04
  • @xxyyxx did you ever figure this out? I'm running into the same issue. – dkniffin Sep 14 '16 at 14:29

0 Answers0