Module: Committee::Test::Methods
- Defined in:
- lib/committee/test/methods.rb
Instance Method Summary collapse
- #assert_request_schema_confirm ⇒ Object
- #assert_response_schema_confirm(expected_status = nil) ⇒ Object
- #assert_schema_conform(expected_status = nil) ⇒ Object
- #committee_options ⇒ Object
- #old_behavior ⇒ Object
- #request_object ⇒ Object
- #response_data ⇒ Object
- #router ⇒ Object
- #schema ⇒ Object
- #schema_coverage ⇒ Object
- #schema_validator ⇒ Object
- #validate_response?(status) ⇒ Boolean
Instance Method Details
#assert_request_schema_confirm ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/committee/test/methods.rb', line 11 def assert_request_schema_confirm unless schema_validator.link_exist? request = "`#{request_object.request_method} #{request_object.path_info}` undefined in schema (prefix: #{[:prefix].inspect})." raise Committee::InvalidRequest.new(request) end schema_validator.request_validate(request_object) end |
#assert_response_schema_confirm(expected_status = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/committee/test/methods.rb', line 20 def assert_response_schema_confirm(expected_status = nil) unless schema_validator.link_exist? response = "`#{request_object.request_method} #{request_object.path_info}` undefined in schema (prefix: #{[:prefix].inspect})." raise Committee::InvalidResponse.new(response) end status, headers, body = response_data if expected_status.nil? Committee.need_good_option('Pass expected response status code to check it against the corresponding schema explicitly.') elsif expected_status != status response = "Expected `#{expected_status}` status code, but it was `#{status}`." raise Committee::InvalidResponse.new(response) end if schema_coverage operation_object = router.operation_object(request_object) schema_coverage&.update_response_coverage!(operation_object.original_path, operation_object.http_method, status) end schema_validator.response_validate(status, headers, [body], true) if validate_response?(status) end |
#assert_schema_conform(expected_status = nil) ⇒ Object
6 7 8 9 |
# File 'lib/committee/test/methods.rb', line 6 def assert_schema_conform(expected_status = nil) assert_request_schema_confirm unless old_behavior assert_response_schema_confirm(expected_status) end |
#committee_options ⇒ Object
43 44 45 |
# File 'lib/committee/test/methods.rb', line 43 def raise "please set options" end |
#old_behavior ⇒ Object
79 80 81 |
# File 'lib/committee/test/methods.rb', line 79 def old_behavior .fetch(:old_assert_behavior, false) end |
#request_object ⇒ Object
47 48 49 |
# File 'lib/committee/test/methods.rb', line 47 def request_object raise "please set object like 'last_request'" end |
#response_data ⇒ Object
51 52 53 |
# File 'lib/committee/test/methods.rb', line 51 def response_data raise "please set response data like 'last_response.status, last_response.headers, last_response.body'" end |
#router ⇒ Object
63 64 65 |
# File 'lib/committee/test/methods.rb', line 63 def router @router ||= schema.build_router() end |
#schema ⇒ Object
59 60 61 |
# File 'lib/committee/test/methods.rb', line 59 def schema @schema ||= Committee::Middleware::Base.get_schema() end |
#schema_coverage ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/committee/test/methods.rb', line 71 def schema_coverage return nil unless schema.is_a?(Committee::Drivers::OpenAPI3::Schema) coverage = .fetch(:schema_coverage, nil) coverage.is_a?(SchemaCoverage) ? coverage : nil end |
#schema_validator ⇒ Object
67 68 69 |
# File 'lib/committee/test/methods.rb', line 67 def schema_validator @schema_validator ||= router.build_schema_validator(request_object) end |
#validate_response?(status) ⇒ Boolean
55 56 57 |
# File 'lib/committee/test/methods.rb', line 55 def validate_response?(status) Committee::Middleware::ResponseValidation.validate?(status, .fetch(:validate_success_only, false)) end |