-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiJson Load errors on be_json_eql matchers #43
Comments
What's your JSON? |
JSON strings must be quoted with double quotes, not single. That may be your issue. |
|
I'm inspecting now and it's weird. Check this out: def parse_json(json, path = nil)
ruby = MultiJson.decode("[#{json}]").first
puts "GOT RUBY: #{ruby}"
v = value_at_json_path(ruby, path)
puts "GOT VALUE: #{v}"
v
rescue MultiJson::DecodeError => e
puts "GOT ERROR"
MultiJson.decode(json)
end gives
|
It's picking up an error even though there isn't one. If I rescue the MultiJson.decode(json) with the @v (value_at_json_path return value), it works and all tests pass. |
Try running it with this: def parse_json(json, path = nil)
puts "GOT JSON: #{json}"
puts "GOT PATH: #{path}"
ruby = MultiJson.decode("[#{json}]").first
puts "GOT RUBY: #{ruby}"
v = value_at_json_path(ruby, path)
puts "GOT VALUE: #{v}"
v
rescue MultiJson::DecodeError => e
puts "GOT ERROR"
MultiJson.decode(json)
end |
|
I think I figured it out (and should have a long time ago). The JSON matchers are meant to compare JSON to JSON. Above, you're comparing JSON to Ruby. So when you give an expected string to the matcher, the matcher figures you're giving it JSON. So it's trying to parse |
Try this |
in my tests:
this passes
this throws MultiJson load error
The text was updated successfully, but these errors were encountered: