Skip to content

Instantly share code, notes, and snippets.

@letmein
Last active December 28, 2015 00:19
Show Gist options
  • Save letmein/7412908 to your computer and use it in GitHub Desktop.
Save letmein/7412908 to your computer and use it in GitHub Desktop.
RSpec matcher for json-schema
RSpec::Matchers.define :match_schema do |schema_name|
match do |json|
schema = Rails.root.join("/path/to/your/schemas/#{schema_name}.json")
@errors = JSON::Validator.fully_validate(schema, json)
@errors.none?
end
failure_message_for_should do
@errors.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment