Module: Committee::Test::Methods
- Defined in:
- lib/committee/test/methods.rb
Instance Method Summary collapse
- #assert_schema_conform ⇒ Object
- #assert_schema_content_type ⇒ Object
-
#committee_schema ⇒ Object
Can be overridden with a different driver name for other API definition formats.
-
#schema_contents ⇒ Object
can be overridden alternatively to #schema_path in case the schema is easier to access as a string blob.
- #schema_path ⇒ Object
- #schema_url_prefix ⇒ Object
- #validate_response?(status) ⇒ Boolean
- #warn_hash_deprecated ⇒ Object
- #warn_string_deprecated ⇒ Object
Instance Method Details
#assert_schema_conform ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/committee/test/methods.rb', line 3 def assert_schema_conform @committee_schema ||= begin # The preferred option. The user has already parsed a schema elsewhere # and we therefore don't have to worry about any performance # implications of having to do it for every single test suite. if committee_schema committee_schema else schema = schema_contents if schema.is_a?(String) warn_string_deprecated elsif schema.is_a?(Hash) warn_hash_deprecated end if schema.is_a?(String) schema = JSON.parse(schema) end if schema.is_a?(Hash) || schema.is_a?(JsonSchema::Schema) driver = Committee::Drivers::HyperSchema.new # The driver itself has its own special cases to be able to parse # either a hash or JsonSchema::Schema object. schema = driver.parse(schema) end schema end end @committee_router ||= Committee::Router.new(@committee_schema, prefix: schema_url_prefix) link, _ = @committee_router.find_request_link(last_request) unless link response = "`#{last_request.request_method} #{last_request.path_info}` undefined in schema." raise Committee::InvalidResponse.new(response) end if validate_response?(last_response.status) data = JSON.parse(last_response.body) Committee::ResponseValidator.new(link).call(last_response.status, last_response.headers, data) end end |
#assert_schema_content_type ⇒ Object
50 51 52 |
# File 'lib/committee/test/methods.rb', line 50 def assert_schema_content_type Committee.warn_deprecated("Committee: use of #assert_schema_content_type is deprecated; use #assert_schema_conform instead.") end |
#committee_schema ⇒ Object
Can be overridden with a different driver name for other API definition formats.
56 57 58 |
# File 'lib/committee/test/methods.rb', line 56 def committee_schema nil end |
#schema_contents ⇒ Object
can be overridden alternatively to #schema_path in case the schema is easier to access as a string blob
63 64 65 |
# File 'lib/committee/test/methods.rb', line 63 def schema_contents JSON.parse(File.read(schema_path)) end |
#schema_path ⇒ Object
67 68 69 |
# File 'lib/committee/test/methods.rb', line 67 def schema_path raise "Please override #committee_schema." end |
#schema_url_prefix ⇒ Object
71 72 73 |
# File 'lib/committee/test/methods.rb', line 71 def schema_url_prefix nil end |
#validate_response?(status) ⇒ Boolean
87 88 89 |
# File 'lib/committee/test/methods.rb', line 87 def validate_response?(status) Committee::ResponseValidator.validate?(status) end |
#warn_hash_deprecated ⇒ Object
75 76 77 78 79 |
# File 'lib/committee/test/methods.rb', line 75 def warn_hash_deprecated Committee.warn_deprecated("Committee: returning a hash from " \ "#schema_contents and using #schema_path is deprecated; please " \ "override #committee_schema instead.") end |
#warn_string_deprecated ⇒ Object
81 82 83 84 85 |
# File 'lib/committee/test/methods.rb', line 81 def warn_string_deprecated Committee.warn_deprecated("Committee: returning a string from " \ "#schema_contents is deprecated; please override #committee_schema " \ "instead.") end |