summaryrefslogtreecommitdiff
path: root/spec/support/api/schema_matcher.rb
blob: dff0dfba675c0de15e55a3cd18b9c5253b8c497e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def schema_path(schema)
  schema_directory = "#{Dir.pwd}/spec/fixtures/api/schemas"
  "#{schema_directory}/#{schema}.json"
end

RSpec::Matchers.define :match_response_schema do |schema, **options|
  match do |response|
    JSON::Validator.validate!(schema_path(schema), response.body, options)
  end
end

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