Skip to content

Instantly share code, notes, and snippets.

@bobthecow
Created July 10, 2012 22:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobthecow/3086558 to your computer and use it in GitHub Desktop.
Save bobthecow/3086558 to your computer and use it in GitHub Desktop.
match_json
require 'json_expressions'
RSpec::Matchers.define :match_json do |expected|
unless JsonExpressions::Matcher === expected
expected = JsonExpressions::Matcher.new(expected)
end
match do |actual|
actual = JSON.parse(actual) if String === actual
expected =~ actual
end
failure_message_for_should do |actual|
"expected #{actual} to match json #{expected}"
end
failure_message_for_should_not do |actual|
"expected #{actual} not to match json #{expected}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment