Contents

Request Async API

@javascript

Background:

  • Given you call:
    ruby
    var gavel = require('gavel');
  • And you define the following "request" variable:
    var request = {
      "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 the following "expected" variable:
    var 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": ""
    };
  • And prepare result variable:
    var validationResult = "booboo";

Scenario: isValidatable

@stable

  • When you call:
    gavel.isValidatable(request, expected, 'request', function(error,result){
      validationResult = result;
    });
  • Then "validationResult" variable will contain:
    true

Scenario: validate

@stable

  • When you call:
    gavel.validate(request, expected, 'request', function(error,result){
      validationResult = result;
    });
  • Then "validationResult" variable will contain:
    { version: "2",
      isValid: true,
      headers:
       { results: [],
         realType: 'application/vnd.apiary.http-headers+json',
         expectedType: 'application/vnd.apiary.http-headers+json',
         validator: 'HeadersJsonExample',
         rawData: { length: 0 } },
      body:
       { results: [],
         realType: 'text/plain',
         expectedType: 'text/plain',
         validator: 'TextDiff',
         rawData: '' } }

Source: features/javascript/request_async_api.feature at v2.0.0, Gavel (MIT license).