This page comes from Gavel 3.0.2. It is not part of the 2.0.0 docs. See the latest Gavel docs.
Request validation
Background:
- Given you call:
ruby
const gavel = require('gavel'); - And you define following HTTP request object:
const real = { "method": "GET", "uri": "/ip", "headers": { "user-agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5", "host": "httpbin.org", "accept": "*/*" }, "body": "" }; - And you define following expected HTTP request object:
const expected = { "headers": { "user-agent": "curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5", "host": "httpbin.org", "accept": "*/*" }, "body": "" };
Scenario: validate
- When you call:
gavel.validate(expected, real); - Then it will return:
{ isValid: true, fields: { headers: { isValid: true, errors: [], realType: 'application/vnd.apiary.http-headers+json', expectedType: 'application/vnd.apiary.http-headers+json', validator: 'HeadersJsonExample', rawData: { length: 0 } }, body: { isValid: true, errors: [], realType: 'text/plain', expectedType: 'text/plain', validator: 'TextDiff', rawData: '' } } }
Source: features/javascript/request.feature at v3.0.2, Gavel (MIT license).