Created
March 25, 2016 22:48
-
-
Save rafops/973bfe5d6ffd227ffe1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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