Class: Fitting::Records::TestUnit::Request
- Inherits:
-
Object
- Object
- Fitting::Records::TestUnit::Request
- Defined in:
- lib/fitting/records/test_unit/request.rb
Instance Method Summary collapse
- #body ⇒ Object
- #documented? ⇒ Boolean
- #documented_requests ⇒ Object
- #documented_responses ⇒ Object
-
#initialize(tested_request, all_documented_requests) ⇒ Request
constructor
A new instance of Request.
- #invalid_json_schemas ⇒ Object
- #method ⇒ Object
- #path ⇒ Object
- #response ⇒ Object
- #response_documented? ⇒ Boolean
- #response_json_schemas ⇒ Object
- #response_json_schemas? ⇒ Boolean
- #test_file_path ⇒ Object
- #test_path ⇒ Object
- #valid_json_schemas ⇒ Object
- #valid_json_schemas? ⇒ Boolean
Constructor Details
#initialize(tested_request, all_documented_requests) ⇒ Request
Returns a new instance of Request.
7 8 9 10 |
# File 'lib/fitting/records/test_unit/request.rb', line 7 def initialize(tested_request, all_documented_requests) @tested_request = tested_request @all_documented_requests = all_documented_requests end |
Instance Method Details
#body ⇒ Object
20 21 22 |
# File 'lib/fitting/records/test_unit/request.rb', line 20 def body @body ||= @tested_request.body end |
#documented? ⇒ Boolean
44 45 46 |
# File 'lib/fitting/records/test_unit/request.rb', line 44 def documented? @documented ||= documented_requests.present? end |
#documented_requests ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/fitting/records/test_unit/request.rb', line 36 def documented_requests @documented_requests ||= @all_documented_requests.inject([]) do |res, documented_request| next res unless @tested_request.method == documented_request.method && documented_request.path.match(@tested_request.path.to_s) res.push(documented_request) end end |
#documented_responses ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/fitting/records/test_unit/request.rb', line 48 def documented_responses @documented_responses ||= documented_requests.inject([]) do |res, documented_request| documented_request.responses.map do |documented_response| next unless documented_response['status'] == response.status.to_s res.push(documented_response) end end.flatten.compact end |
#invalid_json_schemas ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/fitting/records/test_unit/request.rb', line 78 def invalid_json_schemas @invalid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema| next res if JSON::Validator.validate(json_schema, response.body) res.push( json_schema: json_schema, fully_validate: JSON::Validator.fully_validate(json_schema, response.body) ) end.flatten end |
#method ⇒ Object
12 13 14 |
# File 'lib/fitting/records/test_unit/request.rb', line 12 def method @method ||= @tested_request.method end |
#path ⇒ Object
16 17 18 |
# File 'lib/fitting/records/test_unit/request.rb', line 16 def path @path ||= @tested_request.path end |
#response ⇒ Object
24 25 26 |
# File 'lib/fitting/records/test_unit/request.rb', line 24 def response @response ||= @tested_request.response end |
#response_documented? ⇒ Boolean
57 58 59 |
# File 'lib/fitting/records/test_unit/request.rb', line 57 def response_documented? @response_documented ||= documented_responses.present? end |
#response_json_schemas ⇒ Object
61 62 63 64 65 |
# File 'lib/fitting/records/test_unit/request.rb', line 61 def response_json_schemas @response_json_schemas ||= documented_responses.inject([]) do |res, documented_response| res.push(documented_response['json_schemas']) end.flatten end |
#response_json_schemas? ⇒ Boolean
67 68 69 |
# File 'lib/fitting/records/test_unit/request.rb', line 67 def response_json_schemas? @response_json_schemas_present ||= response_json_schemas.present? end |
#test_file_path ⇒ Object
32 33 34 |
# File 'lib/fitting/records/test_unit/request.rb', line 32 def test_file_path @test_file_path ||= @tested_request.group end |
#test_path ⇒ Object
28 29 30 |
# File 'lib/fitting/records/test_unit/request.rb', line 28 def test_path @test_path ||= @tested_request.title end |
#valid_json_schemas ⇒ Object
71 72 73 74 75 76 |
# File 'lib/fitting/records/test_unit/request.rb', line 71 def valid_json_schemas @valid_json_schemas ||= response_json_schemas.inject([]) do |res, json_schema| next res unless JSON::Validator.validate(json_schema, response.body) res.push(json_schema) end.flatten end |
#valid_json_schemas? ⇒ Boolean
88 89 90 |
# File 'lib/fitting/records/test_unit/request.rb', line 88 def valid_json_schemas? @valid_json_schemas_present ||= valid_json_schemas.present? end |