Skip to content

Instantly share code, notes, and snippets.

@rafops
Created March 25, 2016 22:48
Show Gist options
  • Save rafops/973bfe5d6ffd227ffe1d to your computer and use it in GitHub Desktop.
Save rafops/973bfe5d6ffd227ffe1d to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :match_response_schema do |schema,fragment|
match do |response|
puts ""
print "Method:\t\t".magenta
puts request.method.purple
print "Path:\t\t".magenta
puts request.path.purple
print "Request:\t".magenta
puts request.params.select { |p| !['controller', 'action'].include? p }.to_s.purple
print "Response:\t".magenta
puts (begin JSON.parse(response.body) rescue "" end).to_s.purple
puts ""
schema_directory = "#{Dir.pwd}/spec/support/schemas"
fragment = '#/' if fragment.nil?
schema_path = "#{schema_directory}/#{schema}_schema.json"
JSON::Validator.validate!(schema_path, response.body, fragment: fragment)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment