-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Fix test runs for optional dependencies #196
Conversation
cc694d6
to
aa8a9b7
Compare
aa8a9b7
to
16ae726
Compare
Incidentally, if we want to measure test coverage, we need the build to work with |
@@ -6,10 +6,8 @@ module JSON | |||
class Schema | |||
class IPFormat < FormatAttribute | |||
def self.validate(current_schema, data, fragments, processor, validator, options = {}) | |||
return unless data.is_a?(String) |
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.
Actually, this is a mistake - we don't want to do this. The underlying problem is actually in the data the common test suite is using...
77f1a2f
to
74114d1
Compare
Here's the pull request in the common test suite that should fix the build: |
Eek, I can't believe I didn't notice that half of the build matrix wasn't actually running tests any more. =\ The issue here is the same ambiguity we've run into elsewhere; if you're calling TBH I don't know how we can possibly fix this while maintaining the (mis?)feature of allowing |
Ok, bear with me - I have a fix (half finished) |
As things were (with all dev dependencies defined in the Gemfile) the additional gemfiles in ./gemfiles (used for testing optional dependencies) were not requiring additional devdependencies, such as minitest (they were still passing, but were probably using a different version of minitest to the main test runs)
This makes it behave: 1. More like multi json and yajl, which can parse scalar values (not just hashes or arrays) 2. More correctly, in terms of the latest json rfc (rfc7159)* Incidentally both multi_json and rails turn on quirks mode by default. But there are a few other reasons for doing this - before, if json schema was passed a string, then parsing would fail and the string would be passed into the validator as a string. But that string could contain an integer or a float value. That's clearly not the correct behavior.
Instead of requiring it lots of times, and calling it when we don't need to
95e8059
to
9ca5ea4
Compare
This is ready to merge now (pending review, of course). I've added a I'll probably start using that when I use json-schema in rails, because often I want to validate the data in API requests. Rails parses those automatically on the way into the app (based on the mime type) so there's no need to re-parse them. |
attempt to parse the data
9ca5ea4
to
152742d
Compare
I'm having a bit of trouble with the build for this, looks like older versions of json-gem segfault if you try to parse something that's not a string. Will try again later |
Seems like some older versions of the json gem segfault if they're passed anything other than a string. We rely on json raising an error if it's not given a string (in Validator#initialize_data)
Travis was having DNS problems last night so I didn't get a chance to resolve the failures on all platforms. Will try again today some time |
|
||
<pre> | ||
require 'rubygems' | ||
require 'json-schema' |
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.
I think we should generally start leaving these off in the code examples, it's just noisy. It's safe to assume that people will know to require the library they're using.
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.
Yeah that's a good point.
Let me raise an issue so we don't forget
Two minor comments that totally aren't blockers, but huge 👍 in general. Literally every project I use json-schema on will swap over to using this option once this lands. =) edit: the latest travis run had a segfault in rbx that I can't reproduce locally (even with the same seed); I've saved the log here, and triggered a re-run to see if it's a reliable error. It's worth noting that the test run passed just fine, the segfault was after the tests succeeded. |
Looks good to me and I also like the new option 👍 |
Fix test runs for optional dependencies
Thanks guys |
Introduced by conflicts in how voxpupuli#175 and voxpupuli#196 juggled webmock usage. Closes voxpupuli#207.
This has become a bit of a mammoth fix to what I thought was a minor problem!
Here's a rundown of what I've learned:
yajl and multi_json are right - "127.0" should be a float.
What's happening in the json-schema parsing code right now, is that if a json text is passed in and it doesn't parse, then we leave it as a string (then validate that string). However, yajl/multi_json parse "127.0" without errors (and return a number for validation), whereas json-gem throws an error because it (incorrectly) thinks that is invalid json (and then json-schema just uses the original string).
So, my conclusion is that the way we're using json-gem is incorrect right now. But if we switch on quirks mode (which is what mutli_json and rails do) it will parse numbers correctly. So that's what I've done (as well as fixing the optional builds).
This doesn't fix the test failure, but at least all the builds are behaving in the same way. The real problem is in the common test suite (they should be using a string for that particular test, not a float). I'm going to fix the common test suite now, but the code in this PR should be correct.