Created
January 20, 2017 08:21
-
-
Save xenjke/20d4f26f9141f6195740a6b88ac95b53 to your computer and use it in GitHub Desktop.
RSpec JSON schema matcher
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| | |
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