• Sean McGivern's avatar
    Remove duplicate JSON schema matcher · 34b49aec
    Sean McGivern authored
    We had three JSON schema matchers:
    
    1. `match_schema` - takes a data structure and a path to a schema file.
    2. `match_response_schema` - takes a response object and a path to a
       schema file.
    3. `according_to_schema` - chained matcher on `be_valid_json`, takes a
       schema literal.
    
    The reason for this is that we wanted to operate on various axes:
    
    1. Are we validating a parsed data structure, or a potentially-JSON
       string?
    2. 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)
    34b49aec
build_entity_spec.rb 1.46 KB