thoughtworks/pacto — pull request #72 by maxlinc (2013-12-15 20:52:06+00:00)
Title: Improves header validation messages

Header validation has been rather annoying for me so far. It's been produces a lot of false negatives, or at least very trivial difference that most people probably can problem ignore (things like whitespace and ordering of headers which contain lists, like Vary).

When I do run into a problem - real or false negative - it has been hard to pinpoint the problem. This PR improves the messages.

Before:
> expected Pacto to have validated GET https://api.github.com/repos/thoughtbot/factory_girl/contributors
but validation errors were found:
["The property '#/' of type string did not match the following type: array in schema 62584124-b23c-564f-9682-ebeb863abe32#", "Invalid headers: expected {\"Content-Type\"=>\"application/json; charset=utf-8\", \"Status\"=>\"200 OK\", \"Cache-Control\"=>\"public, max-age=60, s-maxage=60\", \"Vary\"=>[\"Accept\", \"Accept-Encoding\"], \"Access-Control-Allow-Credentials\"=>\"true\", \"Access-Control-Expose-Headers\"=>\"ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval\", \"Access-Control-Allow-Origin\"=>\"*\"} to be a subset of {}"]

After:

> Failure/Error: expect(Pacto).to have_validated(:get, 'https://api.github.com/repos/thoughtbot/factory_girl/contributors')
expected Pacto to have validated GET https://api.github.com/repos/thoughtbot/factory_girl/contributors
but validation errors were found:
Missing expected response header: Content-Type
Missing expected response header: Status
Missing expected response header: Cache-Control
Missing expected response header: Vary
Missing expected response header: Access-Control-Allow-Credentials
Missing expected response header: Access-Control-Expose-Headers
Missing expected response header: Access-Control-Allow-Origin

Before:
> ["Invalid headers: expected {\"Content-Type\"=>\"application/json; charset=utf-8\", \"Status\"=>\"200 OK\", \"Cache-Control\"=>\"public, max-age=60, s-maxage=60\", \"Vary\"=>[\"Accept\", \"Accept-Encoding\"], \"Access-Control-Allow-Credentials\"=>\"true\", \"Access-Control-Expose-Headers\"=>\"ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval\", \"Access-Control-Allow-Origin\"=>\"*\"} to be a subset of {\"server\"=>\"GitHub.com\", \"date\"=>\"Sun, 15 Dec 2013 20:49:29 GMT\", \"content-type\"=>\"application/json; charset=utf-8\", \"transfer-encoding\"=>\"chunked\", \"status\"=>\"200 OK\", \"x-ratelimit-limit\"=>\"60\", \"x-ratelimit-remaining\"=>\"58\", \"x-ratelimit-reset\"=>\"1387143664\", \"cache-control\"=>\"public, max-age=60, s-maxage=60\", \"last-modified\"=>\"Sun, 15 Dec 2013 03:33:19 GMT\", \"etag\"=>\"\\\"07bb54cba2c663551e7ac065b7ca9d8a\\\"\", \"vary\"=>\"Accept, Accept-Encoding\", \"x-github-media-type\"=>\"github.beta\", \"x-content-type-options\"=>\"nosniff\", \"access-control-allow-credentials\"=>\"true\", \"access-control-expose-headers\"=>\"ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval\", \"access-control-allow-origin\"=>\"*\", \"x-github-request-id\"=>\"462A9D15:6DA7:C685B8:52AE15D9\"}"]

After:
> Invalid response header Vary: expected ["Accept", "Accept-Encoding"] but received "Accept, Accept-Encoding"