bblimke/webmock — pull request #334 by maxlinc (2013-11-20 19:16:17+00:00)
Title: RFC 6570 (URI Template) support for URIPattern

This is my attempt at adding [RFC 6570](http://tools.ietf.org/html/rfc6570) support to WebMock. WebMock was already using Addressable::URI, this just hooks it into Addressable::Template as well.

I am interested in this because many services I want to mock are using (or starting to use) RFC 6570 URI Templates in their documentation. This let's me copy a URL out of the documentation and straight into WebMock. For example, [OpenStack documentation](https://wiki.openstack.org/wiki/Marconi/specs/api/v1) is using RFC 6570, as does any documentation using [apiary.io](http://support.apiary.io/knowledgebase/articles/106871-uri-templates-support) or [apiblueprint](https://github.com/apiaryio/api-blueprint/blob/21271eaec00c8eef747818763e2d94a3b65e1178/API%20Blueprint%20Specification.md#431-resource-section). GitHub's API docs don't use it, but their API returns RFC 6570 links in the [hypermedia section](http://developer.github.com/v3/#hypermedia), just like [json-hyper-schema](http://json-schema.org/).

I know there's lots of other URI matching systems out there, but I believe the maintenance cost of this would be lower than others, since it is a standard and is implemented by an existing WebMock dependency.

I did come across two issues, though:
* Addressable::Template only seems to support strict matching. If an unknown query parameter is received it will not match the pattern.
* It is tricky to use Addressable::Template along with WebMock's `.with(:query => ...)`, since the former matches full URLs and the latter matches only a portion.

My original implementation raised and exception if you combined Addressable::Template with query_params set via WebMock. I then switched it so that Addressable::Template matches the full URI if no query_params are passed to WebMock. If a query_param is passed, then a warning is displayed and Addressable::Template is used to match the base uri, and WebMock is used to match the query params.