Remove duplicate JSON schema matcher
What does this MR do?
We had three JSON schema matchers:
-
match_schema
- takes a data structure and a path to a schema file. -
match_response_schema
- takes a response object and a path to a schema file. -
according_to_schema
- chained matcher onbe_valid_json
, takes a schema literal.
The reason for this is that we wanted to operate on various axes:
- Are we validating a parsed data structure, or a potentially-JSON string?
- Are we providing a path to a schema file, or a literal data structure representing a schema?
Happily, the library we're using already solves problem 1 for us. https://github.com/ruby-json-schema/json-schema#validation says:
All methods take two arguments, which can be either a JSON string, a file containing JSON, or a Ruby object representing JSON data.
So we just needed to solve concern 2, and we handle that by assuming that if the schema argument is a string, it's not a JSON string representing the schema, but a path to a schema file.
To handle the chaining that according_to_schema
had, we can just use
RSpec's and
method:
be_valid_json.and match_schema(build_info_payload_schema)
See #292255 (closed) and !49348 (comment 462521262) for background.
Closes #292255 (closed).
Edited by Sean McGivern