-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Handle MultiJson ParseErrors #20
base: master
Are you sure you want to change the base?
Conversation
lib/json_matchers/matcher.rb
Outdated
@@ -24,6 +24,8 @@ def matches?(response) | |||
false | |||
rescue JSON::ParserError | |||
raise InvalidSchemaError | |||
rescue MultiJson::ParseError | |||
raise InvalidSchemaError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch!
What do you think about combining the errors on a single line:
rescue JSON::ParserError, MultiJson::ParseError
raise InvalidSchemaError
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sold! Let's do it.
On further inspection, what is the source of the What happens when the multi_json isn't included as a dependency? |
For some reason, it tries to parse the empty string JSON schema in the first rspec test with MultiJson, not the regular JSON validator. I looked up the docs for MultiJson, and it seems to be kind of a catch-all JSON coder. Not sure how Ruby decides between multijson and the regular JSON validator.
|
A small follow up:
|
Previously, the first rspec test was failing because the matcher.rb was only rescuing JSON::ParseErrors but not MultiJson::ParseErrors. For whatever reason, the empty string raised the latter, not the former, error.
With this minor fix, all tests are green.