Created
July 10, 2012 22:15
-
-
Save bobthecow/3086558 to your computer and use it in GitHub Desktop.
match_json
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
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