Class: MethodCaseTest
- Inherits:
-
Object
- Object
- MethodCaseTest
- Defined in:
- lib/tester/method_case_test.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expected_response ⇒ Object
Returns the value of attribute expected_response.
-
#module_name ⇒ Object
Returns the value of attribute module_name.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#reports ⇒ Object
Returns the value of attribute reports.
-
#response ⇒ Object
Returns the value of attribute response.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #check ⇒ Object
- #check_response_code ⇒ Object
- #extra_field_report(field) ⇒ Object
- #increment_fields(seen_fields) ⇒ Object
-
#initialize(response, payload, expected_response, url, verb, module_name) ⇒ MethodCaseTest
constructor
A new instance of MethodCaseTest.
- #json_parse(body) ⇒ Object
- #missing_field_report(field) ⇒ Object
- #response_code_report ⇒ Object
Constructor Details
#initialize(response, payload, expected_response, url, verb, module_name) ⇒ MethodCaseTest
Returns a new instance of MethodCaseTest.
11 12 13 14 15 16 17 18 |
# File 'lib/tester/method_case_test.rb', line 11 def initialize response, payload, expected_response, url, verb, module_name self.payload = payload self.response = response self.expected_response = expected_response self.reports = [] self.url = "#{verb} #{url}" self.module_name = module_name end |
Instance Attribute Details
#expected_response ⇒ Object
Returns the value of attribute expected_response.
4 5 6 |
# File 'lib/tester/method_case_test.rb', line 4 def expected_response @expected_response end |
#module_name ⇒ Object
Returns the value of attribute module_name.
9 10 11 |
# File 'lib/tester/method_case_test.rb', line 9 def module_name @module_name end |
#payload ⇒ Object
Returns the value of attribute payload.
5 6 7 |
# File 'lib/tester/method_case_test.rb', line 5 def payload @payload end |
#reports ⇒ Object
Returns the value of attribute reports.
7 8 9 |
# File 'lib/tester/method_case_test.rb', line 7 def reports @reports end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/tester/method_case_test.rb', line 6 def response @response end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/tester/method_case_test.rb', line 8 def url @url end |
Instance Method Details
#check ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/tester/method_case_test.rb', line 38 def check if check_response_code evaluator = ResponseEvaluator.new json_parse(self.response.body), self.expected_response evaluator.missing_fields.map{|field| missing_field_report(field)} evaluator.extra_fields.map{|field| extra_field_report(field)} increment_fields evaluator.seen_fields end return self.reports end |
#check_response_code ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/tester/method_case_test.rb', line 48 def check_response_code if response.code != expected_response.code response_code_report return false end return true end |
#extra_field_report(field) ⇒ Object
32 33 34 35 36 |
# File 'lib/tester/method_case_test.rb', line 32 def extra_field_report field report = Report.new "#{module_name} - Found extra field #{field}", self.url, self.payload, self.expected_response, self.response self.reports << report nil end |
#increment_fields(seen_fields) ⇒ Object
56 57 58 59 60 |
# File 'lib/tester/method_case_test.rb', line 56 def increment_fields seen_fields seen_fields.each do |field| field.seen end end |
#json_parse(body) ⇒ Object
62 63 64 65 66 |
# File 'lib/tester/method_case_test.rb', line 62 def json_parse body JSON.parse!(body) rescue JSON::ParserError body end |
#missing_field_report(field) ⇒ Object
26 27 28 29 30 |
# File 'lib/tester/method_case_test.rb', line 26 def missing_field_report field report = Report.new "#{module_name} - Missing field #{field}", self.url, self.payload, self.expected_response, self.response self.reports << report nil end |
#response_code_report ⇒ Object
20 21 22 23 24 |
# File 'lib/tester/method_case_test.rb', line 20 def response_code_report report = StatusCodeReport.new "#{module_name} - Incorrect response code", self.url, self.payload, self.expected_response.code, self.response.code self.reports << report nil end |