-
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
return size of 0 if json ruby value is nil #80
Conversation
This scenario failed from the master |
@eluns The I can't say that I agree with the presumption that Rather than evaluating Thank you! I'll close this pull request in favor of a future request buttoning up the matcher's failure messaging. |
Hi Steve, |
} | ||
""" | ||
When I get the JSON | ||
Then the JSON at "array_with_null" should have 1 entry |
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 agree that this assertion should pass.
Hi Steve, Thanks, |
@actual = 0 | ||
else | ||
@actual = Enumerable === ruby ? ruby.size : 1 | ||
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.
It might be more appropriate (and less surprising) to change this to something like:
ruby = parse_json(json, @path)
raise EnumerableExpected.new("Enumerable expected, got #{ruby.inspect}.") unless Enumerable === ruby
@actual = ruby.size
@actual == @expected
Of course, we'd have to define the error class, write tests, etc.
Hi Steve, |
An entry can be null such as [null], which is 1 entry. If a null is a value of an Array, then the array has 0 entry. However a null value returns a size of 1
def matches?(json)
ruby = parse_json(json, @path)
#when ruby = nil
#NoMethodError: undefined method `size' for nil:NilClass
# so @Actual = 1 when ruby is nil
@Actual = Enumerable === ruby ? ruby.size : 1
@Actual == @expected
end