From e84a0cf362b864bb5e81e2a1abaab5c12c01700a Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 24 May 2019 16:06:16 +0200 Subject: [PATCH 01/26] feat: removes "isValidatable" from public API BREAKING CHANGE: Removes "isValidatable" from public API --- features/javascript/request_async_api.feature | 13 ------------- features/javascript/request_sync_api.feature | 11 ----------- features/javascript/response_async_api.feature | 13 ------------- features/javascript/response_sync_api.feature | 11 ----------- 4 files changed, 48 deletions(-) diff --git a/features/javascript/request_async_api.feature b/features/javascript/request_async_api.feature index 48542a9..80a3b2c 100644 --- a/features/javascript/request_async_api.feature +++ b/features/javascript/request_async_api.feature @@ -36,19 +36,6 @@ Feature: Request Async API var validationResult = "booboo"; """ - @stable - Scenario: isValidatable - When you call: - """ - gavel.isValidatable(request, expected, 'request', function(error,result){ - validationResult = result; - }); - """ - Then "validationResult" variable will contain: - """ - true - """ - @stable Scenario: validate When you call: diff --git a/features/javascript/request_sync_api.feature b/features/javascript/request_sync_api.feature index 67e562c..8304daf 100644 --- a/features/javascript/request_sync_api.feature +++ b/features/javascript/request_sync_api.feature @@ -46,17 +46,6 @@ Feature: request Sync API true """ - @stables - Scenario: isValidatable - When you call: - """ - request.isValidatable(); - """ - Then it will return: - """ - true - """ - @stable Scenario: validate When you call: diff --git a/features/javascript/response_async_api.feature b/features/javascript/response_async_api.feature index ef5f63e..e0485bf 100644 --- a/features/javascript/response_async_api.feature +++ b/features/javascript/response_async_api.feature @@ -41,19 +41,6 @@ Feature: Response Async API var validationResult = "booboo"; """ - @stable - Scenario: isValidatable - When you call: - """ - gavel.isValidatable(response, expected, 'response', function(error,result){ - validationResult = result; - }); - """ - Then "validationResult" variable will contain: - """ - true - """ - @stable Scenario: validate When you call: diff --git a/features/javascript/response_sync_api.feature b/features/javascript/response_sync_api.feature index 759c1db..0e96835 100644 --- a/features/javascript/response_sync_api.feature +++ b/features/javascript/response_sync_api.feature @@ -51,17 +51,6 @@ Feature: Response Sync API true """ - @stable - Scenario: isValidatable - When you call: - """ - response.isValidatable(); - """ - Then it will return: - """ - true - """ - @stable Scenario: validate When you call: From ac26d1d72cd74dc8ed9afa884097fc118fc51418 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 24 May 2019 16:11:05 +0200 Subject: [PATCH 02/26] feat: remove "isValid" from public API --- features/javascript/README.md | 2 +- features/javascript/request_sync_api.feature | 11 ----------- features/javascript/response_sync_api.feature | 11 ----------- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/features/javascript/README.md b/features/javascript/README.md index 0d9503e..55b7895 100644 --- a/features/javascript/README.md +++ b/features/javascript/README.md @@ -42,7 +42,7 @@ const expectedResponse = { 'body': '{\n "origin": "94.113.241.2"\n}' }; -gavel.isValid(actualResponse, expectedResponse, 'response', (err, result) => { +gavel.validate(actualResponse, expectedResponse, 'response', (err, result) => { if (err) { console.error(err); } else { diff --git a/features/javascript/request_sync_api.feature b/features/javascript/request_sync_api.feature index 8304daf..318def2 100644 --- a/features/javascript/request_sync_api.feature +++ b/features/javascript/request_sync_api.feature @@ -35,17 +35,6 @@ Feature: request Sync API request.expected = expected; """ - @stable - Scenario: isValid - When you call: - """ - request.isValid(); - """ - Then it will return: - """ - true - """ - @stable Scenario: validate When you call: diff --git a/features/javascript/response_sync_api.feature b/features/javascript/response_sync_api.feature index 0e96835..21c389b 100644 --- a/features/javascript/response_sync_api.feature +++ b/features/javascript/response_sync_api.feature @@ -40,17 +40,6 @@ Feature: Response Sync API response.expected = expected; """ - @stable - Scenario: isValid - When you call: - """ - response.isValid(); - """ - Then it will return: - """ - true - """ - @stable Scenario: validate When you call: From 9c1f450cf267fe524166757835d24bde2f3afb50 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 24 May 2019 16:30:38 +0200 Subject: [PATCH 03/26] feat: adds "method" expectation suite --- features/expectations/method.feature | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 features/expectations/method.feature diff --git a/features/expectations/method.feature b/features/expectations/method.feature new file mode 100644 index 0000000..04d89b8 --- /dev/null +++ b/features/expectations/method.feature @@ -0,0 +1,15 @@ +@stable +Feature: Method + + Background: + Given you expect HTTP message method "POST" + + Scenario: Different HTTP message method + When real HTTP message method is "GET" + Then Gavel will set some errors for "method" + And Request or Response is NOT valid + + Scenario: HTTP message method match + When real method is "POST" + Then Gavel will NOT set any errors for "method" + And Request or Response is valid From f77a1120b2f2593a05dcb524544ddac346dcc174 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 27 May 2019 10:24:48 +0200 Subject: [PATCH 04/26] feat: removes references to "HttpRequest" and "HttpResponse" classes --- features/javascript/request_sync_api.feature | 18 +++++++----------- features/javascript/response_sync_api.feature | 18 +++++++----------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/features/javascript/request_sync_api.feature b/features/javascript/request_sync_api.feature index 318def2..95f5586 100644 --- a/features/javascript/request_sync_api.feature +++ b/features/javascript/request_sync_api.feature @@ -6,9 +6,9 @@ Feature: request Sync API """ var gavel = require('gavel'); """ - And you define following "Httprequest" object: + And you define following HTTP request object: """ - var request = new gavel.HttpRequest({ + var request = { "method": "GET", "uri": "/ip", "headers": { @@ -17,29 +17,25 @@ Feature: request Sync API "accept": "*/*" }, "body": "" - }); + }; """ - And you define following "ExpectedHttpRequest" object: + And you define following expected HTTP request object: """ - var expected = new gavel.ExpectedHttpRequest({ + 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 you add expected "request" to real "request": - """ - request.expected = expected; + }; """ @stable Scenario: validate When you call: """ - request.validate(); + gavel.validate(request, expected); """ Then it will return: """ diff --git a/features/javascript/response_sync_api.feature b/features/javascript/response_sync_api.feature index 21c389b..33a88c1 100644 --- a/features/javascript/response_sync_api.feature +++ b/features/javascript/response_sync_api.feature @@ -6,9 +6,9 @@ Feature: Response Sync API """ var gavel = require('gavel'); """ - And you define following "HttpResponse" object: + And you define following HTTP response object: """ - var response = new gavel.HttpResponse({ + var response = { "statusCode": "200", "statusMessage": "OK", "headers": { @@ -19,11 +19,11 @@ Feature: Response Sync API "connection": "keep-alive" }, "body": "{\n \"origin\": \"94.113.241.2\"\n}" - }); + }; """ - And you define following "ExpectedHttpResponse" object: + And you define following expected HTTP response object: """ - var expected = new gavel.ExpectedHttpResponse({ + var expected = { "statusCode": "200", "headers": { "content-type": "application/json", @@ -33,18 +33,14 @@ Feature: Response Sync API "connection": "keep-alive" }, "body": "{\n \"origin\": \"94.113.241.2\"\n}", - }); - """ - And you add expected "response" to real "response": - """ - response.expected = expected; + }; """ @stable Scenario: validate When you call: """ - response.validate(); + gavel.validate(response, expected); """ Then it will return: """ From 8feb224a8b781310d132616e4a8dc536220e1b11 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 27 May 2019 10:26:45 +0200 Subject: [PATCH 05/26] feat: removes async API --- ...t_sync_api.feature => request_api.feature} | 0 features/javascript/request_async_api.feature | 63 ---------------- ..._sync_api.feature => response_api.feature} | 0 .../javascript/response_async_api.feature | 74 ------------------- 4 files changed, 137 deletions(-) rename features/javascript/{request_sync_api.feature => request_api.feature} (100%) delete mode 100644 features/javascript/request_async_api.feature rename features/javascript/{response_sync_api.feature => response_api.feature} (100%) delete mode 100644 features/javascript/response_async_api.feature diff --git a/features/javascript/request_sync_api.feature b/features/javascript/request_api.feature similarity index 100% rename from features/javascript/request_sync_api.feature rename to features/javascript/request_api.feature diff --git a/features/javascript/request_async_api.feature b/features/javascript/request_async_api.feature deleted file mode 100644 index 80a3b2c..0000000 --- a/features/javascript/request_async_api.feature +++ /dev/null @@ -1,63 +0,0 @@ -@javascript - -Feature: Request Async API - - Background: - Given you call: - """ - 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"; - """ - - @stable - Scenario: validate - 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: '' } } - """ \ No newline at end of file diff --git a/features/javascript/response_sync_api.feature b/features/javascript/response_api.feature similarity index 100% rename from features/javascript/response_sync_api.feature rename to features/javascript/response_api.feature diff --git a/features/javascript/response_async_api.feature b/features/javascript/response_async_api.feature deleted file mode 100644 index e0485bf..0000000 --- a/features/javascript/response_async_api.feature +++ /dev/null @@ -1,74 +0,0 @@ -@javascript - -Feature: Response Async API - - Background: - Given you call: - """ - var gavel = require('gavel'); - """ - And you define the following "response" variable: - """ - var response = { - "statusCode": "200", - "statusMessage": "OK", - "headers": { - "content-type": "application/json", - "date": "Wed, 03 Jul 2013 13:30:53 GMT", - "server": "gunicorn/0.17.4", - "content-length": "30", - "connection": "keep-alive" - }, - "body": "{\n \"origin\": \"94.113.241.2\"\n}" - }; - """ - And you define the following "expected" variable: - """ - var expected = { - "statusCode": "200", - "headers": { - "content-type": "application/json", - "date": "Wed, 03 Jul 2013 13:30:53 GMT", - "server": "gunicorn/0.17.4", - "content-length": "30", - "connection": "keep-alive" - }, - "body": "{\n \"origin\": \"94.113.241.2\"\n}" - }; - """ - And prepare result variable: - """ - var validationResult = "booboo"; - """ - - @stable - Scenario: validate - When you call: - """ - gavel.validate(response, expected, 'response', 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: 'application/json', - expectedType: 'application/json', - validator: 'JsonExample', - rawData: { length: 0 } }, - statusCode: - { realType: 'text/vnd.apiary.status-code', - expectedType: 'text/vnd.apiary.status-code', - validator: 'TextDiff', - rawData: '', - results: [] } } - """ From d581f81555e668eaa10e37fae150bd3d58c3db21 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Tue, 28 May 2019 10:48:22 +0200 Subject: [PATCH 06/26] feat: removes "version" from validation results --- features/javascript/request_api.feature | 3 +-- features/javascript/response_api.feature | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index 95f5586..b67cb52 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -39,8 +39,7 @@ Feature: request Sync API """ Then it will return: """ - { version: "2", - isValid: true, + { isValid: true, headers: { results: [], realType: 'application/vnd.apiary.http-headers+json', diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 33a88c1..79c211b 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -44,8 +44,7 @@ Feature: Response Sync API """ Then it will return: """ - { version: "2", - isValid: true, + { isValid: true, headers: { results: [], realType: 'application/vnd.apiary.http-headers+json', From bcd5c9e9320cb20c8f6f60ea77b34606ad4b43ae Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 31 May 2019 10:39:59 +0200 Subject: [PATCH 07/26] feat: lists HTTP message fields under "field" key BREAKING CHANGE: Validation result now lists validated HTTP message fields under "field" key --- features/javascript/request_api.feature | 29 ++++++++------- features/javascript/response_api.feature | 45 ++++++++++++++---------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index b67cb52..7805229 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -40,16 +40,21 @@ Feature: request Sync API Then it will return: """ { 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: '' } } + field: { + 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: '' + } + }, + } """ diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 79c211b..46f4677 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -44,23 +44,30 @@ Feature: Response Sync API """ Then it will return: """ - { 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: 'application/json', - expectedType: 'application/json', - validator: 'JsonExample', - rawData: { length: 0 } }, - statusCode: - { realType: 'text/vnd.apiary.status-code', - expectedType: 'text/vnd.apiary.status-code', - validator: 'TextDiff', - rawData: '', - results: [] } } + { + isValid: true, + field: { + headers: { + results: [], + realType: 'application/vnd.apiary.http-headers+json', + expectedType: 'application/vnd.apiary.http-headers+json', + validator: 'HeadersJsonExample', + rawData: { length: 0 } + }, + body: { + results: [], + realType: 'application/json', + expectedType: 'application/json', + validator: 'JsonExample', + rawData: { length: 0 } + }, + statusCode: { + realType: 'text/vnd.apiary.status-code', + expectedType: 'text/vnd.apiary.status-code', + validator: 'TextDiff', + rawData: '', + results: [] + } + } + } """ From 9c91c7d113a3c49dd86be3c046c327c746d6ce0e Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 31 May 2019 10:43:37 +0200 Subject: [PATCH 08/26] feat: replaces "results" key with "errors" BREAKING CHANGE: Validation errors of each individual HTTP message field are now listed in the "errors" key --- features/javascript/request_api.feature | 4 ++-- features/javascript/response_api.feature | 6 +++--- features/validators.feature | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index 7805229..3d57847 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -42,14 +42,14 @@ Feature: request Sync API { isValid: true, field: { headers: { - results: [], + errors: [], realType: 'application/vnd.apiary.http-headers+json', expectedType: 'application/vnd.apiary.http-headers+json', validator: 'HeadersJsonExample', rawData: { length: 0 } }, body: { - results: [], + errors: [], realType: 'text/plain', expectedType: 'text/plain', validator: 'TextDiff', diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 46f4677..89a7de7 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -48,25 +48,25 @@ Feature: Response Sync API isValid: true, field: { headers: { - results: [], + errors: [], realType: 'application/vnd.apiary.http-headers+json', expectedType: 'application/vnd.apiary.http-headers+json', validator: 'HeadersJsonExample', rawData: { length: 0 } }, body: { - results: [], + errors: [], realType: 'application/json', expectedType: 'application/json', validator: 'JsonExample', rawData: { length: 0 } }, statusCode: { + errors: [] realType: 'text/vnd.apiary.status-code', expectedType: 'text/vnd.apiary.status-code', validator: 'TextDiff', rawData: '', - results: [] } } } diff --git a/features/validators.feature b/features/validators.feature index 876335b..23fc383 100644 --- a/features/validators.feature +++ b/features/validators.feature @@ -8,14 +8,14 @@ Feature: Data validators and output format **realType** - required - Media Type of real data **expectedType** - optional - Media Type of expected (example) data used for validation **validator** - optional - Data validator used for real and expected data comparison - **results** - required - Validation result errors and warnings + **errors** - required - Validation result errors and warnings **rawData** - optional - Raw output from the data validator When you perform a failing validation on any validatable HTTP component Then the validator output for the HTTP component looks like the following JSON: """ { - "results": [ + "errors": [ { "pointer": "/c", "severity": "error", @@ -44,7 +44,7 @@ Feature: Data validators and output format "type": "object", "$schema": "http://json-schema.org/draft-04/schema", "id": "#", - "required": [ "realType", "results" ], + "required": [ "realType", "errors" ], "properties": { "realType": { "type": "string", @@ -67,7 +67,7 @@ Feature: Data validators and output format } ] }, - "results": { + "errors": { "default": { "pointer": "/missingKeyInRealData", "message": "Key is missing", @@ -92,8 +92,8 @@ Feature: Data validators and output format } } """ - And each result entry under "results" key must contain "message" key - And each result entry under "results" key must contain "severity" key + And each result entry under "errors" key must contain "message" key + And each result entry under "errors" key must contain "severity" key And validated HTTP component is considered invalid And the output JSON contains key "validator" with one of the following values: | JsonSchema | @@ -132,7 +132,7 @@ Feature: Data validators and output format +girl who """ - And validation key "results" looks like the following "JSON": + And validation key "errors" looks like the following "JSON": """ [ { @@ -174,7 +174,7 @@ Feature: Data validators and output format When you perform validation on the HTTP component Then validator "JsonSchema" is used for validation - And validation key "results" looks like the following "JSON": + And validation key "errors" looks like the following "JSON": """ [ { @@ -219,7 +219,7 @@ Feature: Data validators and output format When you perform validation on the HTTP component Then validator "JsonExample" is used for validation - And validation key "results" looks like the following "JSON": + And validation key "errors" looks like the following "JSON": """ [ { From c5663f64d4bebedb86dc9337d26902a469927e3f Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 31 May 2019 11:02:07 +0200 Subject: [PATCH 09/26] feat: sets "isValid" property on each HTTP message field result --- features/expectations/body_json_example.feature | 1 + features/expectations/body_json_schema.feature | 4 +++- features/expectations/body_json_schemav3.feature | 3 +++ features/expectations/body_text_example.feature | 4 ++++ features/expectations/headers.feature | 4 ++++ features/expectations/method.feature | 2 ++ features/expectations/status_code.feature | 6 ++++-- features/javascript/request_api.feature | 2 ++ features/javascript/response_api.feature | 3 +++ 9 files changed, 26 insertions(+), 3 deletions(-) diff --git a/features/expectations/body_json_example.feature b/features/expectations/body_json_example.feature index ba7f2f5..1eb0521 100644 --- a/features/expectations/body_json_example.feature +++ b/features/expectations/body_json_example.feature @@ -74,6 +74,7 @@ Feature: Body - JSON example } """ Then Gavel will NOT set any errors for "body" + And Gavel will set "isValid" to "true" for "body" And Request or Response is valid Scenario: Extra array member in real JSON body diff --git a/features/expectations/body_json_schema.feature b/features/expectations/body_json_schema.feature index 6791ef4..393e0eb 100644 --- a/features/expectations/body_json_schema.feature +++ b/features/expectations/body_json_schema.feature @@ -45,7 +45,9 @@ Feature: Body - JSON schema draft v4 } """ Then Gavel will NOT set any errors for "body" + And Gavel will set "isValid" to "true" for "body" And Request or Response is valid + Scenario: Payload body not valid against schema When real HTTP body is following: """ @@ -58,5 +60,5 @@ Feature: Body - JSON schema draft v4 } """ Then Gavel will set some error for "body" + And Gavel will set "isValid" to "false" for "body" And Request or Response is NOT valid - diff --git a/features/expectations/body_json_schemav3.feature b/features/expectations/body_json_schemav3.feature index 906e9c7..90fc631 100644 --- a/features/expectations/body_json_schemav3.feature +++ b/features/expectations/body_json_schemav3.feature @@ -48,7 +48,9 @@ Feature: Body - JSON schema draft v3 } """ Then Gavel will NOT set any errors for "body" + And Gavel will set "isValid" to "true" for body And Request or Response is valid + Scenario: Payload body not valid against schema When real HTTP body is following: """ @@ -61,4 +63,5 @@ Feature: Body - JSON schema draft v3 } """ Then Gavel will set some error for "body" + And Gavel will set "isValid" to "false" for "body" And Request or Response is NOT valid diff --git a/features/expectations/body_text_example.feature b/features/expectations/body_text_example.feature index f30b640..a7713a5 100644 --- a/features/expectations/body_text_example.feature +++ b/features/expectations/body_text_example.feature @@ -16,6 +16,7 @@ Feature: Body - text example Orange, strawberry, banana? """ Then Gavel will set some error for "body" + And Gavel will set "isValid" to "false" for "body" And Request or Response is NOT valid Scenario: Extra line in real payload textual body @@ -27,6 +28,7 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will set some error for "body" + And Gavel will set "isValid" to "false" for "body" And Request or Response is NOT valid Scenario: Line is changed in real textual body @@ -37,6 +39,7 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will set some error for "body" + And Gavel will set "isValid" to "false" for "body" And Request or Response is NOT valid Scenario: Text in body equals defined example @@ -47,5 +50,6 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will NOT set any errors for "body" + And Gavel will set "isValid" to "true" for "body" And Request or Response is valid diff --git a/features/expectations/headers.feature b/features/expectations/headers.feature index 2f83cf6..24cd10a 100644 --- a/features/expectations/headers.feature +++ b/features/expectations/headers.feature @@ -18,6 +18,7 @@ Feature: Headers Content-Type: text/plain """ Then Gavel will set some error for "headers" + And Gavel will set "isValid" to "false" for "headers" And Request or Response is NOT valid @stable @@ -31,6 +32,7 @@ Feature: Headers ETag: 68b329da9893e34099c7d8ad5cb9c940 """ Then Gavel will NOT set any errors for "headers" + And Gavel will set "isValid" to "true" for "headers" And Request or Response is valid @stable @@ -43,6 +45,7 @@ Feature: Headers ETag: 68b329da9893e34099c7d8ad5cb9c940 """ Then Gavel will set some error for "headers" + And Gavel will set "isValid" to "false" for "headers" And Request or Response is NOT valid @stable @@ -55,6 +58,7 @@ Feature: Headers ETag: something-completely-different """ Then Gavel will NOT set any errors for "headers" + And Gavel will set "isValid" to "true" for "body" And Request or Response is valid diff --git a/features/expectations/method.feature b/features/expectations/method.feature index 04d89b8..51aca64 100644 --- a/features/expectations/method.feature +++ b/features/expectations/method.feature @@ -7,9 +7,11 @@ Feature: Method Scenario: Different HTTP message method When real HTTP message method is "GET" Then Gavel will set some errors for "method" + And Gavel will set "isValid" to "false" for "method" And Request or Response is NOT valid Scenario: HTTP message method match When real method is "POST" Then Gavel will NOT set any errors for "method" + And Gavel will set "isValid" to "true" for "method" And Request or Response is valid diff --git a/features/expectations/status_code.feature b/features/expectations/status_code.feature index c7175c1..6646c20 100644 --- a/features/expectations/status_code.feature +++ b/features/expectations/status_code.feature @@ -6,10 +6,12 @@ Feature: Status code Scenario: Different real response status When real status code is "500" - Then Gavel will set some error for "status code" + Then Gavel will set some error for "statusCode" + And Gavel will set "isValid" to "false" for "statusCode" And Request or Response is NOT valid Scenario: Response status code match When real status code is "200" - Then Gavel will NOT set any errors for "status code" + Then Gavel will NOT set any errors for "statusCode" + And Gavel will set "isValid" to "true" for "statusCode" And Request or Response is valid diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index 3d57847..ce7a7eb 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -42,6 +42,7 @@ Feature: request Sync API { isValid: true, field: { headers: { + isValid: true, errors: [], realType: 'application/vnd.apiary.http-headers+json', expectedType: 'application/vnd.apiary.http-headers+json', @@ -49,6 +50,7 @@ Feature: request Sync API rawData: { length: 0 } }, body: { + isValid: true, errors: [], realType: 'text/plain', expectedType: 'text/plain', diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 89a7de7..d0fb278 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -48,6 +48,7 @@ Feature: Response Sync API isValid: true, field: { headers: { + isValid: true, errors: [], realType: 'application/vnd.apiary.http-headers+json', expectedType: 'application/vnd.apiary.http-headers+json', @@ -55,6 +56,7 @@ Feature: Response Sync API rawData: { length: 0 } }, body: { + isValid: true, errors: [], realType: 'application/json', expectedType: 'application/json', @@ -62,6 +64,7 @@ Feature: Response Sync API rawData: { length: 0 } }, statusCode: { + isValid: true, errors: [] realType: 'text/vnd.apiary.status-code', expectedType: 'text/vnd.apiary.status-code', From f58471482502aa53be16ecae0aa9a6203b5dc354 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Fri, 31 May 2019 11:02:39 +0200 Subject: [PATCH 10/26] feat: adds "uri" validation feature suite --- features/expectations/uri.feature | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 features/expectations/uri.feature diff --git a/features/expectations/uri.feature b/features/expectations/uri.feature new file mode 100644 index 0000000..dea5592 --- /dev/null +++ b/features/expectations/uri.feature @@ -0,0 +1,17 @@ +@stable +Feature: URI + + Background: + Given you expect HTTP message URI "http://apiary.io/path" + + Scenario: Different HTTP message URI + When real HTTP message URI is "http://foo.bar" + Then Gavel will set some errors for "uri" + And Gavel will set "isValid" to "false" for "uri" + And Request or Response is NOT valid + + Scenario: HTTP message URI match + When real HTTP message URI is "http://apiary.io/path" + Then Gavel will NOT set any errors for "uri" + And Gavel will set "isValid" to "true" for "uri" + And Request or Response is valid From da0173681d86167777337652859e8ce836569921 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 3 Jun 2019 15:10:52 +0300 Subject: [PATCH 11/26] fix: wraps target property in quotes --- features/expectations/body_json_schemav3.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/expectations/body_json_schemav3.feature b/features/expectations/body_json_schemav3.feature index 90fc631..a503f82 100644 --- a/features/expectations/body_json_schemav3.feature +++ b/features/expectations/body_json_schemav3.feature @@ -48,7 +48,7 @@ Feature: Body - JSON schema draft v3 } """ Then Gavel will NOT set any errors for "body" - And Gavel will set "isValid" to "true" for body + And Gavel will set "isValid" to "true" for "body" And Request or Response is valid Scenario: Payload body not valid against schema From 6a8ed7ceb4b0adbddd2cc445e0155db293e697da Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 3 Jun 2019 15:11:28 +0300 Subject: [PATCH 12/26] fix: includes "isValid" key in expected validation result (validators) --- features/validators.feature | 1 + 1 file changed, 1 insertion(+) diff --git a/features/validators.feature b/features/validators.feature index 23fc383..5901b8a 100644 --- a/features/validators.feature +++ b/features/validators.feature @@ -15,6 +15,7 @@ Feature: Data validators and output format Then the validator output for the HTTP component looks like the following JSON: """ { + "isValid": false, "errors": [ { "pointer": "/c", From dcda152fb0f404d25aa90cf656be323502b57640 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 3 Jun 2019 15:17:52 +0300 Subject: [PATCH 13/26] fix: renames "body" to "headers" in validity assertion (headers) --- features/expectations/headers.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/expectations/headers.feature b/features/expectations/headers.feature index 24cd10a..b57e169 100644 --- a/features/expectations/headers.feature +++ b/features/expectations/headers.feature @@ -58,7 +58,7 @@ Feature: Headers ETag: something-completely-different """ Then Gavel will NOT set any errors for "headers" - And Gavel will set "isValid" to "true" for "body" + And Gavel will set "isValid" to "true" for "headers" And Request or Response is valid From bd7b2586551137e33acab340d364c2a84c7f91a4 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 10:40:33 +0300 Subject: [PATCH 14/26] refactor: uses es6 variables declaration in code examples --- features/javascript/request_api.feature | 13 +++++++------ features/javascript/response_api.feature | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index ce7a7eb..ef20ef7 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -1,14 +1,14 @@ @javascript -Feature: request Sync API +Feature: Request validation Background: Given you call: """ - var gavel = require('gavel'); + const gavel = require('gavel'); """ And you define following HTTP request object: """ - var request = { + const request = { "method": "GET", "uri": "/ip", "headers": { @@ -21,7 +21,7 @@ Feature: request Sync API """ And you define following expected HTTP request object: """ - var expected = { + 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", @@ -39,7 +39,8 @@ Feature: request Sync API """ Then it will return: """ - { isValid: true, + { + isValid: true, field: { headers: { isValid: true, @@ -57,6 +58,6 @@ Feature: request Sync API validator: 'TextDiff', rawData: '' } - }, + } } """ diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index d0fb278..32f9b64 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -1,14 +1,14 @@ @javascript -Feature: Response Sync API +Feature: Response validation Background: Given you call: """ - var gavel = require('gavel'); + const gavel = require('gavel'); """ And you define following HTTP response object: """ - var response = { + const response = { "statusCode": "200", "statusMessage": "OK", "headers": { @@ -23,7 +23,7 @@ Feature: Response Sync API """ And you define following expected HTTP response object: """ - var expected = { + const expected = { "statusCode": "200", "headers": { "content-type": "application/json", @@ -65,11 +65,11 @@ Feature: Response Sync API }, statusCode: { isValid: true, - errors: [] + errors: [], realType: 'text/vnd.apiary.status-code', expectedType: 'text/vnd.apiary.status-code', validator: 'TextDiff', - rawData: '', + rawData: '' } } } From 808ad9e6735577bee4437d888062e3b5f859d5c3 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 11:05:18 +0300 Subject: [PATCH 15/26] fix: uses implementation-agnostic phrasing for field validity definition --- features/expectations/body_json_example.feature | 2 +- features/expectations/body_json_schema.feature | 2 +- features/expectations/body_json_schemav3.feature | 2 +- features/expectations/body_text_example.feature | 6 +++--- features/expectations/headers.feature | 8 ++++---- features/expectations/method.feature | 14 +++++++------- features/expectations/status_code.feature | 14 +++++++------- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/features/expectations/body_json_example.feature b/features/expectations/body_json_example.feature index 1eb0521..a4cc80a 100644 --- a/features/expectations/body_json_example.feature +++ b/features/expectations/body_json_example.feature @@ -74,7 +74,7 @@ Feature: Body - JSON example } """ Then Gavel will NOT set any errors for "body" - And Gavel will set "isValid" to "true" for "body" + And field "body" is valid And Request or Response is valid Scenario: Extra array member in real JSON body diff --git a/features/expectations/body_json_schema.feature b/features/expectations/body_json_schema.feature index 393e0eb..563c96e 100644 --- a/features/expectations/body_json_schema.feature +++ b/features/expectations/body_json_schema.feature @@ -45,7 +45,7 @@ Feature: Body - JSON schema draft v4 } """ Then Gavel will NOT set any errors for "body" - And Gavel will set "isValid" to "true" for "body" + And field "body" is valid And Request or Response is valid Scenario: Payload body not valid against schema diff --git a/features/expectations/body_json_schemav3.feature b/features/expectations/body_json_schemav3.feature index a503f82..4e3dce4 100644 --- a/features/expectations/body_json_schemav3.feature +++ b/features/expectations/body_json_schemav3.feature @@ -48,7 +48,7 @@ Feature: Body - JSON schema draft v3 } """ Then Gavel will NOT set any errors for "body" - And Gavel will set "isValid" to "true" for "body" + And field "body" is valid And Request or Response is valid Scenario: Payload body not valid against schema diff --git a/features/expectations/body_text_example.feature b/features/expectations/body_text_example.feature index a7713a5..947325d 100644 --- a/features/expectations/body_text_example.feature +++ b/features/expectations/body_text_example.feature @@ -28,7 +28,7 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will set some error for "body" - And Gavel will set "isValid" to "false" for "body" + And field "body" is NOT valid And Request or Response is NOT valid Scenario: Line is changed in real textual body @@ -39,7 +39,7 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will set some error for "body" - And Gavel will set "isValid" to "false" for "body" + And field "body" is NOT valid And Request or Response is NOT valid Scenario: Text in body equals defined example @@ -50,6 +50,6 @@ Feature: Body - text example Dog, cat, mouse! """ Then Gavel will NOT set any errors for "body" - And Gavel will set "isValid" to "true" for "body" + And field "body" is valid And Request or Response is valid diff --git a/features/expectations/headers.feature b/features/expectations/headers.feature index b57e169..1bd6ede 100644 --- a/features/expectations/headers.feature +++ b/features/expectations/headers.feature @@ -18,7 +18,7 @@ Feature: Headers Content-Type: text/plain """ Then Gavel will set some error for "headers" - And Gavel will set "isValid" to "false" for "headers" + And field "headers" is NOT valid And Request or Response is NOT valid @stable @@ -32,7 +32,7 @@ Feature: Headers ETag: 68b329da9893e34099c7d8ad5cb9c940 """ Then Gavel will NOT set any errors for "headers" - And Gavel will set "isValid" to "true" for "headers" + And field "headers" is valid And Request or Response is valid @stable @@ -45,7 +45,7 @@ Feature: Headers ETag: 68b329da9893e34099c7d8ad5cb9c940 """ Then Gavel will set some error for "headers" - And Gavel will set "isValid" to "false" for "headers" + And field "headers" is NOT valid And Request or Response is NOT valid @stable @@ -58,7 +58,7 @@ Feature: Headers ETag: something-completely-different """ Then Gavel will NOT set any errors for "headers" - And Gavel will set "isValid" to "true" for "headers" + And field "headers" is valid And Request or Response is valid diff --git a/features/expectations/method.feature b/features/expectations/method.feature index 51aca64..4518aad 100644 --- a/features/expectations/method.feature +++ b/features/expectations/method.feature @@ -4,14 +4,14 @@ Feature: Method Background: Given you expect HTTP message method "POST" - Scenario: Different HTTP message method - When real HTTP message method is "GET" - Then Gavel will set some errors for "method" - And Gavel will set "isValid" to "false" for "method" - And Request or Response is NOT valid - Scenario: HTTP message method match When real method is "POST" Then Gavel will NOT set any errors for "method" - And Gavel will set "isValid" to "true" for "method" + And field "method" is valid And Request or Response is valid + + Scenario: Different HTTP message method + When real HTTP message method is "GET" + Then Gavel will set some errors for "method" + And field "method" is NOT valid + And Request or Response is NOT valid diff --git a/features/expectations/status_code.feature b/features/expectations/status_code.feature index 6646c20..9bcfb54 100644 --- a/features/expectations/status_code.feature +++ b/features/expectations/status_code.feature @@ -4,14 +4,14 @@ Feature: Status code Background: Given you expect HTTP status code "200" - Scenario: Different real response status - When real status code is "500" - Then Gavel will set some error for "statusCode" - And Gavel will set "isValid" to "false" for "statusCode" - And Request or Response is NOT valid - Scenario: Response status code match When real status code is "200" Then Gavel will NOT set any errors for "statusCode" - And Gavel will set "isValid" to "true" for "statusCode" + And field "statusCode" is valid And Request or Response is valid + + Scenario: Different real response status + When real status code is "500" + Then Gavel will set some error for "statusCode" + And field "statusCode" is NOT valid + And Request or Response is NOT valid From 2a364e22360b24916c046575a3f311bee1598c4b Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 11:07:48 +0300 Subject: [PATCH 16/26] feat: removes "severity" property from validation errors BREAKING CHANGE: Validation errors no longer have "severity" property. --- features/validators.feature | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/features/validators.feature b/features/validators.feature index 5901b8a..9399670 100644 --- a/features/validators.feature +++ b/features/validators.feature @@ -19,7 +19,6 @@ Feature: Data validators and output format "errors": [ { "pointer": "/c", - "severity": "error", "message": "At '/c' Missing required property: c" } ], @@ -71,21 +70,16 @@ Feature: Data validators and output format "errors": { "default": { "pointer": "/missingKeyInRealData", - "message": "Key is missing", - "severity": "error" + "message": "Key is missing" }, "type": "array", "items": { "type": "object", - "required": ["message", "severity"], + "required": ["message"], "properties": { "message": { "type": "string", "default": "No validator found for real data type." - }, - "severity": { - "type": "string", - "default": "errors" } } } @@ -94,7 +88,6 @@ Feature: Data validators and output format } """ And each result entry under "errors" key must contain "message" key - And each result entry under "errors" key must contain "severity" key And validated HTTP component is considered invalid And the output JSON contains key "validator" with one of the following values: | JsonSchema | @@ -137,8 +130,7 @@ Feature: Data validators and output format """ [ { - "message": "Real and expected data does not match.", - "severity": "error" + "message": "Real and expected data does not match." } ] """ @@ -180,7 +172,6 @@ Feature: Data validators and output format [ { "pointer": "/a", - "severity": "error", "message": "At '/a' Missing required property: a" } ] @@ -225,12 +216,10 @@ Feature: Data validators and output format [ { "pointer": "/a", - "severity": "error", "message": "At '/a' Missing required property: a" }, { "pointer": "/missingKeyInRealData", - "severity": "error", "message": "At '/missingKeyInRealData' Missing required property: missingKeyInRealData" } ] From 78238560f07884d89a73417e507897b2c952e920 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 11:09:34 +0300 Subject: [PATCH 17/26] fix: stores HTTP message fields under "fields" property, not "field" --- features/javascript/request_api.feature | 2 +- features/javascript/response_api.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index ef20ef7..b38479c 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -41,7 +41,7 @@ Feature: Request validation """ { isValid: true, - field: { + fields: { headers: { isValid: true, errors: [], diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 32f9b64..2a6153e 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -46,7 +46,7 @@ Feature: Response validation """ { isValid: true, - field: { + fields: { headers: { isValid: true, errors: [], From 1f2d29f271af182b43e60f2cbb978a081ea9435d Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 14:50:08 +0300 Subject: [PATCH 18/26] feat: swaps the order of "real" and "expected" arguments of "validate" BREAKING CHANGE: Gavel's "validate" method now has the following call signature: validate(expected, real) --- features/javascript/request_api.feature | 4 ++-- features/javascript/response_api.feature | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/javascript/request_api.feature b/features/javascript/request_api.feature index b38479c..08c2ba9 100644 --- a/features/javascript/request_api.feature +++ b/features/javascript/request_api.feature @@ -8,7 +8,7 @@ Feature: Request validation """ And you define following HTTP request object: """ - const request = { + const real = { "method": "GET", "uri": "/ip", "headers": { @@ -35,7 +35,7 @@ Feature: Request validation Scenario: validate When you call: """ - gavel.validate(request, expected); + gavel.validate(expected, real); """ Then it will return: """ diff --git a/features/javascript/response_api.feature b/features/javascript/response_api.feature index 2a6153e..823b8ea 100644 --- a/features/javascript/response_api.feature +++ b/features/javascript/response_api.feature @@ -8,7 +8,7 @@ Feature: Response validation """ And you define following HTTP response object: """ - const response = { + const real = { "statusCode": "200", "statusMessage": "OK", "headers": { @@ -40,7 +40,7 @@ Feature: Response validation Scenario: validate When you call: """ - gavel.validate(response, expected); + gavel.validate(expected, real); """ Then it will return: """ From 2a8475d0db9aee97fcc3c09faddc9808009a22dd Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Wed, 5 Jun 2019 14:51:30 +0300 Subject: [PATCH 19/26] fix: uses non-implementational behavior descriptions for body expectations --- features/expectations/body_json_schema.feature | 2 +- features/expectations/body_json_schemav3.feature | 2 +- features/expectations/body_text_example.feature | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/features/expectations/body_json_schema.feature b/features/expectations/body_json_schema.feature index 563c96e..f646c4b 100644 --- a/features/expectations/body_json_schema.feature +++ b/features/expectations/body_json_schema.feature @@ -60,5 +60,5 @@ Feature: Body - JSON schema draft v4 } """ Then Gavel will set some error for "body" - And Gavel will set "isValid" to "false" for "body" + And field "body" is NOT valid And Request or Response is NOT valid diff --git a/features/expectations/body_json_schemav3.feature b/features/expectations/body_json_schemav3.feature index 4e3dce4..733f738 100644 --- a/features/expectations/body_json_schemav3.feature +++ b/features/expectations/body_json_schemav3.feature @@ -63,5 +63,5 @@ Feature: Body - JSON schema draft v3 } """ Then Gavel will set some error for "body" - And Gavel will set "isValid" to "false" for "body" + And field "body" is NOT valid And Request or Response is NOT valid diff --git a/features/expectations/body_text_example.feature b/features/expectations/body_text_example.feature index 947325d..1af66c8 100644 --- a/features/expectations/body_text_example.feature +++ b/features/expectations/body_text_example.feature @@ -16,7 +16,7 @@ Feature: Body - text example Orange, strawberry, banana? """ Then Gavel will set some error for "body" - And Gavel will set "isValid" to "false" for "body" + And field "body" is NOT valid And Request or Response is NOT valid Scenario: Extra line in real payload textual body From bb81f9d2f96fa38fe2f130fa148f8b566975172d Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 6 Jun 2019 12:16:08 +0300 Subject: [PATCH 20/26] fix: removes duplicate "will (NOT) set errors on "X") criteria --- features/expectations/body_json_example.feature | 9 ++++----- features/expectations/body_json_schema.feature | 6 ++---- features/expectations/body_json_schemav3.feature | 6 ++---- features/expectations/body_text_example.feature | 12 ++++-------- features/expectations/headers.feature | 12 ++++-------- features/expectations/method.feature | 6 ++---- features/expectations/status_code.feature | 6 ++---- 7 files changed, 20 insertions(+), 37 deletions(-) diff --git a/features/expectations/body_json_example.feature b/features/expectations/body_json_example.feature index a4cc80a..72ec28a 100644 --- a/features/expectations/body_json_example.feature +++ b/features/expectations/body_json_example.feature @@ -33,7 +33,7 @@ Feature: Body - JSON example "string": "Hello World" } """ - Then Gavel will set some error for "body" + Then field "body" is NOT valid And Request or Response is NOT valid Scenario: Extra key in real JSON body @@ -53,7 +53,7 @@ Feature: Body - JSON example "boolean": true } """ - Then Gavel will NOT set any errors for "body" + Then field "body" is valid And Request or Response is valid Scenario: Different values in real JSON body @@ -73,8 +73,7 @@ Feature: Body - JSON example "boolean": false } """ - Then Gavel will NOT set any errors for "body" - And field "body" is valid + Then field "body" is valid And Request or Response is valid Scenario: Extra array member in real JSON body @@ -94,6 +93,6 @@ Feature: Body - JSON example "string": "Foo bar" } """ - Then Gavel will NOT set any errors for "body" + Then field "body" is valid And Request or Response is valid diff --git a/features/expectations/body_json_schema.feature b/features/expectations/body_json_schema.feature index f646c4b..e3439f6 100644 --- a/features/expectations/body_json_schema.feature +++ b/features/expectations/body_json_schema.feature @@ -44,8 +44,7 @@ Feature: Body - JSON schema draft v4 "string": "Hello World" } """ - Then Gavel will NOT set any errors for "body" - And field "body" is valid + Then field "body" is valid And Request or Response is valid Scenario: Payload body not valid against schema @@ -59,6 +58,5 @@ Feature: Body - JSON schema draft v4 "string": "Hello World" } """ - Then Gavel will set some error for "body" - And field "body" is NOT valid + Then field "body" is NOT valid And Request or Response is NOT valid diff --git a/features/expectations/body_json_schemav3.feature b/features/expectations/body_json_schemav3.feature index 733f738..4d8330e 100644 --- a/features/expectations/body_json_schemav3.feature +++ b/features/expectations/body_json_schemav3.feature @@ -47,8 +47,7 @@ Feature: Body - JSON schema draft v3 "string": "Hello World" } """ - Then Gavel will NOT set any errors for "body" - And field "body" is valid + Then field "body" is valid And Request or Response is valid Scenario: Payload body not valid against schema @@ -62,6 +61,5 @@ Feature: Body - JSON schema draft v3 "string": "Hello World" } """ - Then Gavel will set some error for "body" - And field "body" is NOT valid + Then field "body" is NOT valid And Request or Response is NOT valid diff --git a/features/expectations/body_text_example.feature b/features/expectations/body_text_example.feature index 1af66c8..2e3b16f 100644 --- a/features/expectations/body_text_example.feature +++ b/features/expectations/body_text_example.feature @@ -15,8 +15,7 @@ Feature: Body - text example One, two, three, four. Orange, strawberry, banana? """ - Then Gavel will set some error for "body" - And field "body" is NOT valid + Then field "body" is NOT valid And Request or Response is NOT valid Scenario: Extra line in real payload textual body @@ -27,8 +26,7 @@ Feature: Body - text example Orange, strawberry, banana? Dog, cat, mouse! """ - Then Gavel will set some error for "body" - And field "body" is NOT valid + Then field "body" is NOT valid And Request or Response is NOT valid Scenario: Line is changed in real textual body @@ -38,8 +36,7 @@ Feature: Body - text example Orange, strawberry, banana? Dog, cat, mouse! """ - Then Gavel will set some error for "body" - And field "body" is NOT valid + Then field "body" is NOT valid And Request or Response is NOT valid Scenario: Text in body equals defined example @@ -49,7 +46,6 @@ Feature: Body - text example Orange, strawberry, banana? Dog, cat, mouse! """ - Then Gavel will NOT set any errors for "body" - And field "body" is valid + Then field "body" is valid And Request or Response is valid diff --git a/features/expectations/headers.feature b/features/expectations/headers.feature index 1bd6ede..0e4af9e 100644 --- a/features/expectations/headers.feature +++ b/features/expectations/headers.feature @@ -17,8 +17,7 @@ Feature: Headers """ Content-Type: text/plain """ - Then Gavel will set some error for "headers" - And field "headers" is NOT valid + Then field "headers" is NOT valid And Request or Response is NOT valid @stable @@ -31,8 +30,7 @@ Feature: Headers Location: /here ETag: 68b329da9893e34099c7d8ad5cb9c940 """ - Then Gavel will NOT set any errors for "headers" - And field "headers" is valid + Then field "headers" is valid And Request or Response is valid @stable @@ -44,8 +42,7 @@ Feature: Headers Location: /here ETag: 68b329da9893e34099c7d8ad5cb9c940 """ - Then Gavel will set some error for "headers" - And field "headers" is NOT valid + Then field "headers" is NOT valid And Request or Response is NOT valid @stable @@ -57,8 +54,7 @@ Feature: Headers Location: /there ETag: something-completely-different """ - Then Gavel will NOT set any errors for "headers" - And field "headers" is valid + Then field "headers" is valid And Request or Response is valid diff --git a/features/expectations/method.feature b/features/expectations/method.feature index 4518aad..7b3bf09 100644 --- a/features/expectations/method.feature +++ b/features/expectations/method.feature @@ -6,12 +6,10 @@ Feature: Method Scenario: HTTP message method match When real method is "POST" - Then Gavel will NOT set any errors for "method" - And field "method" is valid + Then field "method" is valid And Request or Response is valid Scenario: Different HTTP message method When real HTTP message method is "GET" - Then Gavel will set some errors for "method" - And field "method" is NOT valid + Then field "method" is NOT valid And Request or Response is NOT valid diff --git a/features/expectations/status_code.feature b/features/expectations/status_code.feature index 9bcfb54..06527cc 100644 --- a/features/expectations/status_code.feature +++ b/features/expectations/status_code.feature @@ -6,12 +6,10 @@ Feature: Status code Scenario: Response status code match When real status code is "200" - Then Gavel will NOT set any errors for "statusCode" - And field "statusCode" is valid + Then field "statusCode" is valid And Request or Response is valid Scenario: Different real response status When real status code is "500" - Then Gavel will set some error for "statusCode" - And field "statusCode" is NOT valid + Then field "statusCode" is NOT valid And Request or Response is NOT valid From a2f83572cbc7834a6693441ae497b13a6dfaa84e Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 6 Jun 2019 12:27:28 +0300 Subject: [PATCH 21/26] refactor: updates README usage example --- features/javascript/README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/features/javascript/README.md b/features/javascript/README.md index 55b7895..0e5e40f 100644 --- a/features/javascript/README.md +++ b/features/javascript/README.md @@ -19,7 +19,7 @@ npm install gavel ```javascript const gavel = require('gavel'); -const actualResponse = { +const expectedResponse = { 'statusCode': '200', 'headers': { 'content-type': 'application/json', @@ -30,7 +30,8 @@ const actualResponse = { }, 'body': '{\n "origin": "94.113.241.2"\n}' }; -const expectedResponse = { + +const realResponse = { 'statusCode': '200', 'headers': { 'content-type': 'application/json', @@ -42,13 +43,7 @@ const expectedResponse = { 'body': '{\n "origin": "94.113.241.2"\n}' }; -gavel.validate(actualResponse, expectedResponse, 'response', (err, result) => { - if (err) { - console.error(err); - } else { - console.log(result); - } -}); +const result = gavel.validate(expectedResponse, realResponse); ``` ### Command-line interface From cf50d5edb4c8a04e8e14fe7fda5752d44e1a416d Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 6 Jun 2019 14:19:51 +0300 Subject: [PATCH 22/26] feat: adds "uri" validation feature --- features/expectations/uri.feature | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/features/expectations/uri.feature b/features/expectations/uri.feature index dea5592..8feb05c 100644 --- a/features/expectations/uri.feature +++ b/features/expectations/uri.feature @@ -2,16 +2,14 @@ Feature: URI Background: - Given you expect HTTP message URI "http://apiary.io/path" - - Scenario: Different HTTP message URI - When real HTTP message URI is "http://foo.bar" - Then Gavel will set some errors for "uri" - And Gavel will set "isValid" to "false" for "uri" - And Request or Response is NOT valid + Given you expect HTTP message URI "https://domain.com/path" Scenario: HTTP message URI match - When real HTTP message URI is "http://apiary.io/path" - Then Gavel will NOT set any errors for "uri" - And Gavel will set "isValid" to "true" for "uri" + When real HTTP message URI is "http://foo.bar" + Then field "uri" is valid And Request or Response is valid + + Scenario: Different HTTP message URI + When real HTTP message URI is "https://domain.com/path" + Then field "uri" is NOT valid + And Request or Response is NOT valid From f7ffc14835ac373bc8150559a1d4897af0fe0275 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 6 Jun 2019 14:25:54 +0300 Subject: [PATCH 23/26] fix: includes relative URI in feature definition --- features/expectations/uri.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/expectations/uri.feature b/features/expectations/uri.feature index 8feb05c..0986b59 100644 --- a/features/expectations/uri.feature +++ b/features/expectations/uri.feature @@ -2,14 +2,14 @@ Feature: URI Background: - Given you expect HTTP message URI "https://domain.com/path" + Given you expect HTTP message URI "/animals?type=cats" Scenario: HTTP message URI match - When real HTTP message URI is "http://foo.bar" + When real HTTP message URI is "/animals?type=cats" Then field "uri" is valid And Request or Response is valid Scenario: Different HTTP message URI - When real HTTP message URI is "https://domain.com/path" + When real HTTP message URI is "/animals?type=dogs" Then field "uri" is NOT valid And Request or Response is NOT valid From 8112483986eff711131a1c500a0e4a59bdae93c9 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 6 Jun 2019 15:15:54 +0300 Subject: [PATCH 24/26] chore: removes "_api" suffix from request/response validation features --- features/javascript/{request_api.feature => request.feature} | 0 features/javascript/{response_api.feature => response.feature} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename features/javascript/{request_api.feature => request.feature} (100%) rename features/javascript/{response_api.feature => response.feature} (100%) diff --git a/features/javascript/request_api.feature b/features/javascript/request.feature similarity index 100% rename from features/javascript/request_api.feature rename to features/javascript/request.feature diff --git a/features/javascript/response_api.feature b/features/javascript/response.feature similarity index 100% rename from features/javascript/response_api.feature rename to features/javascript/response.feature From 8796e685651827ea20604de7b189805825e2ba72 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 13 Jun 2019 12:47:43 +0200 Subject: [PATCH 25/26] fix: adds proper indentation for "response.feature" --- features/javascript/response.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/javascript/response.feature b/features/javascript/response.feature index 823b8ea..ed4fa12 100644 --- a/features/javascript/response.feature +++ b/features/javascript/response.feature @@ -14,9 +14,9 @@ Feature: Response validation "headers": { "content-type": "application/json", "date": "Wed, 03 Jul 2013 13:30:53 GMT", - "server": "gunicorn/0.17.4", - "content-length": "30", - "connection": "keep-alive" + "server": "gunicorn/0.17.4", + "content-length": "30", + "connection": "keep-alive" }, "body": "{\n \"origin\": \"94.113.241.2\"\n}" }; From 8711aa1a87ecf9b25b0c7e95bdc23eea8fc8de60 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Mon, 17 Jun 2019 10:06:41 +0200 Subject: [PATCH 26/26] feat: removing "data_model" feature BREAKING CHANGE: Gavel spec no longer has "data_model" feature describing operable HTTP messages. --- features/data_model.feature | 155 ------------------------------------ 1 file changed, 155 deletions(-) delete mode 100644 features/data_model.feature diff --git a/features/data_model.feature b/features/data_model.feature deleted file mode 100644 index 8c40fed..0000000 --- a/features/data_model.feature +++ /dev/null @@ -1,155 +0,0 @@ -@javascript @stable -Feature: Data model - - Scenario: HTTP Request - When you have the following real HTTP request: - """ - GET /ip HTTP/1.1 - 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: */* - """ - Then "HTTP Request" JSON representation will look like this: - """ - { - "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": "" - } - """ - - Scenario: HTTP Response - When you have the following real HTTP response: - """ - HTTP/1.1 200 OK - Content-Type: application/json - Date: Wed, 03 Jul 2013 13:30:53 GMT - Server: gunicorn/0.17.4 - Content-Length: 30 - Connection: keep-alive - - { - "origin": "94.113.241.2" - } - """ - - Then "HTTP Response" JSON representation will look like this: - """ - { - "statusCode": "200", - "statusMessage": "OK", - "headers": { - "content-type": "application/json", - "date": "Wed, 03 Jul 2013 13:30:53 GMT", - "server": "gunicorn/0.17.4", - "content-length": "30", - "connection": "keep-alive" - }, - "body": "{\n \"origin\": \"94.113.241.2\"\n}" - } - """ - - - - - Scenario: Expected HTTP Response - When you expect HTTP status code "200" - - And you expect the following HTTP headers: - """ - Content-Type: application/json - Date: Wed, 03 Jul 2013 13:30:53 GMT - Server: gunicorn/0.17.4 - Content-Length: 30 - Connection: keep-alive - """ - - And you define expected HTTP body using the following "JSON example": - """ - { - "origin": "94.113.241.2" - } - """ - - And you define expected HTTP body using the following "JSON schema": - """ - { - "type":"object", - "$schema": "http://json-schema.org/draft-03/schema", - "required":true, - "properties":{ - "object": { - "type":"object", - "required":false, - "properties":{ - "origin": { - "type":"string", - "required":true - } - } - } - } - } - """ - - Then "Expected HTTP Response" JSON representation will look like this: - """ - { - "statusCode": "200", - "headers": { - "content-type": "application/json", - "date": "Wed, 03 Jul 2013 13:30:53 GMT", - "server": "gunicorn/0.17.4", - "content-length": "30", - "connection": "keep-alive" - }, - "body": "{\n \"origin\": \"94.113.241.2\"\n}", - "bodySchema": { - "type": "object", - "$schema": "http://json-schema.org/draft-03/schema", - "required": true, - "properties": { - "object": { - "type": "object", - "required": false, - "properties": { - "origin": { - "type": "string", - "required": true - } - } - } - } - } - } - """ - - Scenario: Expected HTTP Request - When you expect the following HTTP 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: */* - """ - - And you define expected HTTP body using the following "textual example": - """ - MyVariableOne=ValueOne&MyVariableTwo=ValueTwo - """ - - Then "Expected HTTP Request" JSON representation will look like this: - """ - { - "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": "MyVariableOne=ValueOne&MyVariableTwo=ValueTwo" - } - """