fakeweb
fakeweb copied to clipboard
NetConnectNotAllowedError reports the URI different than what is acually being matched.
The problem is that prior to matching, the URI is passed through normalize_uri
which mangles it.
For example:
> require 'fakeweb'
> FakeWeb.allow_net_connect = false
> FakeWeb.register_uri(:get, /http:\/\/good\.com\/\?a=1\&b=2/, :body => "good")
> FakeWeb.register_uri(:get, /http:\/\/bad\.com\/\?b=1\&a=2/, :body => "bad")
> Net::HTTP.get('good.com', '/?a=1&b=2')
"good"
> Net::HTTP.get('bad.com', '/?b=1&a=2')
FakeWeb::NetConnectNotAllowedError: Real HTTP connections are disabled. Unregistered request: GET http://bad.com/?b=1&a=2
which is incredibly confusing, given that error message contains exactly the same URL that I passed in, while in reality match happens against the URL with normalized parameters (see https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/registry.rb#L58)
Looks like normalize_uri
does nothing to Regexp
: https://github.com/chrisk/fakeweb/blob/master/lib/fake_web/registry.rb#L106
normalize_uri
normalizes not the match expression (/http:\/\/bad\.com\/\?b=1\&a=2/
), but the source URI (http://bad.com/?b=1&a=2
), which happens to be a String :stuck_out_tongue:
I see. I didn't realize it was being called from multiple places. Thanks for the clarification.