I want to mock NetHTTP requests but some should be allowed.
require "open-uri"
require "webmock"
WebMock.enable!
When I declare an allowed request like this:
WebMock.disable_net_connect! allow: /\Ahttps:\/\/graph\.facebook\.com\/v2\.8\/debug_token\?access_token=/
and call:
open("https://graph.facebook.com/v2.8/debug_token?access_token=qwerty", &:read)
I get this:
HTTP connections are disabled. Unregistered request: GET https://graph.facebook.com/v2.8/debug_token?access_token=qwerty with headers ...
You can stub this request with the following snippet:
stub_request(:get, "https://graph.facebook.com/v2.8/debug_token?access_token=qwerty").
...
It also fails with regex like this:
/\Ahttps:\/\/graph\.facebook\.com\//
but does not fail with this:
/\Ahttps:\/\/graph\.facebook\.com/
How to allow the full regex that I initially wanted? Why even the \/
after hostname fails matching?