-
Notifications
You must be signed in to change notification settings - Fork 577
Matching
WebMock will match all different representations of the same URI.
I.e all the following representations of the URI are equal:
"www.example.com"
"www.example.com/"
"www.example.com:80"
"www.example.com:80/"
"http://www.example.com"
"http://www.example.com/"
"http://www.example.com:80"
"http://www.example.com:80/"The following URIs with userinfo are also equal for WebMock
"a b:pass@www.example.com"
"a b:pass@www.example.com/"
"a b:pass@www.example.com:80"
"a b:pass@www.example.com:80/"
"http://a b:pass@www.example.com"
"http://a b:pass@www.example.com/"
"http://a b:pass@www.example.com:80"
"http://a b:pass@www.example.com:80/"
"a%20b:pass@www.example.com"
"a%20b:pass@www.example.com/"
"a%20b:pass@www.example.com:80"
"a%20b:pass@www.example.com:80/"
"http://a%20b:pass@www.example.com"
"http://a%20b:pass@www.example.com/"
"http://a%20b:pass@www.example.com:80"
"http://a%20b:pass@www.example.com:80/"or these
"www.example.com/my path/?a=my param&b=c"
"www.example.com/my%20path/?a=my%20param&b=c"
"www.example.com:80/my path/?a=my param&b=c"
"www.example.com:80/my%20path/?a=my%20param&b=c"
"http://www.example.com/my path/?a=my param&b=c"
"http://www.example.com/my%20path/?a=my%20param&b=c"
"http://www.example.com:80/my path/?a=my param&b=c"
"http://www.example.com:80/my%20path/?a=my%20param&b=c"If you provide Regexp to match URI, WebMock will try to match it against every valid form of the same url.
I.e /my path/ will match www.example.com/my%20path because it is equivalent of www.example.com/my path
If you use Addressable::Template for matching, then WebMock will defer the matching rules to Addressable, which complies with RFC 6570.
If you use any of the WebMock methods for matching query params, then Addressable will be used to match the base URI and WebMock will match the query params. If you do not, then WebMock will let Addressable match the full URI.
WebMock will match request headers against stubbed request headers in the following situations:
- Stubbed request has headers specified and request headers are the same as stubbed headers
i.estubbed headers: { 'Header1' => 'Value1', 'Header2' => 'Value2' }, requested: { 'Header1' => 'Value1', 'Header2' => 'Value2' } - Stubbed request has headers specified and stubbed request headers are a subset of request headers
i.estubbed headers: { 'Header1' => 'Value1' }, requested: { 'Header1' => 'Value1', 'Header2' => 'Value2' } - Stubbed request has no headers
i.estubbed headers: nil, requested: { 'Header1' => 'Value1', 'Header2' => 'Value2' }
WebMock normalises headers and treats all forms of same headers as equal
i.e the following two sets of headers are equal:
{ "Header1" => "value1", content_length: 123, X_CuStOm_hEAder: :value }
{ header1: "value1", "Content-Length" => 123, "x-cuSTOM-HeAder" => "value" }