Validating the FormKeep API
FormKeep’s administrative interface is an Ember application that consumes a Rails-backed JSON API. We test our JSON endpoints with RSpec’s request specs . Ensuring that the client and server adhere to a common contract is important. Without test coverage, the contract is implicit and often times brittle. Implementation changes on the server that change JSON payloads in unexpected ways pose problems for consumers. To guard against unexpected changes, we created json_matchers to validate the format of our JSON endpoints, making our contract explicit. Under the covers, json_matchers validates payloads against schemas conforming to the JSON Schema specification. Schemas serve as a codification of the client-server contract. Asserting responses adhere to a JSON Schema In order to verify that GET /api/forms serves JSON in the format our client expects, we’ll assert that it succe...