BigW Consortium Gitlab

schema_matcher.rb 459 Bytes
Newer Older
1 2 3 4 5
def schema_path(schema)
  schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas"
  "#{schema_directory}/#{schema}.json"
end

6
RSpec::Matchers.define :match_response_schema do |schema, **options|
7
  match do |response|
8 9 10
    JSON::Validator.validate!(schema_path(schema), response.body, options)
  end
end
11

12 13 14
RSpec::Matchers.define :match_schema do |schema, **options|
  match do |data|
    JSON::Validator.validate!(schema_path(schema), data, options)
15 16
  end
end