Class: ApiTester::UnexpectedFieldsTest
- Inherits:
-
MethodCaseTest
- Object
- MethodCaseTest
- ApiTester::UnexpectedFieldsTest
- Defined in:
- lib/api-tester/modules/unexpected_fields.rb
Overview
Test layout for UnexpectedFields module
Instance Attribute Summary
Attributes inherited from MethodCaseTest
#expected_response, #module_name, #payload, #reports, #response, #url
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(response, url, method) ⇒ UnexpectedFieldsTest
constructor
A new instance of UnexpectedFieldsTest.
Methods inherited from MethodCaseTest
#check_response_code, #extra_field_report, #increment_fields, #json_parse, #missing_field_report, #response_code_report
Constructor Details
#initialize(response, url, method) ⇒ UnexpectedFieldsTest
Returns a new instance of UnexpectedFieldsTest.
32 33 34 35 36 37 38 39 |
# File 'lib/api-tester/modules/unexpected_fields.rb', line 32 def initialize(response, url, method) super response: response, payload: method.request.default_payload, expected_response: method.expected_response, url: url, verb: method.verb, module_name: 'UnexpectedFieldsModule' end |
Instance Method Details
#check ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/api-tester/modules/unexpected_fields.rb', line 41 def check evaluator = ApiTester::ResponseEvaluator.new actual_body: json_parse(response.body), expected_fields: expected_response response_fields = evaluator.response_field_array expected_fields = evaluator.expected_fields increment_fields evaluator.seen_fields extra = response_fields - expected_fields extra.each do |extra_field| report = Report.new description: "UnexpectedFieldsModule - Found unexpected field #{extra_field}", url: url, request: payload, expected_response: expected_response, actual_response: response reports << report end reports end |