Skip to content

Instantly share code, notes, and snippets.

@xenjke
Created January 20, 2017 08:21
Show Gist options
  • Save xenjke/20d4f26f9141f6195740a6b88ac95b53 to your computer and use it in GitHub Desktop.
Save xenjke/20d4f26f9141f6195740a6b88ac95b53 to your computer and use it in GitHub Desktop.
RSpec JSON schema matcher
RSpec::Matchers.define :match_response_schema do |schema|
errors = []
schema_directory = "#{Dir.pwd}/spec/support"
schema_path = "#{schema_directory}/#{schema}.json"
match do |request|
errors << JSON::Validator.fully_validate(schema_path, request.response, strict: false)
errors.flatten!.empty?
end
failure_message do |request|
"#{request.report_data}\r\n"\
"#{errors.join("\r\n")}\r\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment