JSON matcher updated (works with Rspec 1.3.1). Put this in
spec/support/matchers/json_matcher.rb:
Spec::Matchers.define :be_json_eql do | expected |
match do | actual |
@expected = decode(expected, 'expected')
@actual = decode(actual, 'actual')
@actual == @expected
end
failure_message_for_should do | actual |
"expected\n#{actual}\n" +
"to be JSON code equivalent to\n#{expected}\n" +
"Difference:\n#{@expected.diff(@actual).inspect}"
end
failure_message_for_should_not do | actual |
"expected\n#{actual}\n" +
"to be JSON code different from\n#{expected}"
end
def decode(s, which)
ActiveSupport::JSON.decode(s)
rescue ActiveSupport::JSON::ParseError
raise ArgumentError, "Invalid #{which} JSON string:
#{s.inspect}"
end
end
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users