-
-
Notifications
You must be signed in to change notification settings - Fork 284
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
HaveValue matcher fails with nil value even when negated #600
Comments
/cc @thediveo for his thoughts I believe the intention is to explicitly not allow comparisons when the pointer is One way of reading it is "I'm expecting |
Yes, this design is on purpose to avoid treating |
I can see the motivation for the matcher to fail when the value is nil, that makes sense, I'm still struggling to grasp though the motivation that I guess by your design I'm holding it wrong and I need to have the At a minimum I think we should make mention of this in the docs as I expect others will be surprised by the negation behaviour of |
No you don't hold it wrong. It's a slightly opinionated dresign to err on the safe side, and this meaning in unit tests to not consider nil in this matcher to be an ordinary value, negation or not. Even if this rule sounds odd, but you cannot negate errors, only matches. In cases where I myself find me needing this in many places I put a custom matcher in m of a simple combined set of matchers. |
Does this issue need action and which one? Would improved documentation help and what should we improve? Or would it be in the "works as designed"? |
I would suggest adding a note to the docs of the matcher, something along the lines of
Wdyt? |
Thank you very much for the issue report! |
I was trying to use the
HaveValue
matcher to check a*string
field is not a particular value. However, of course, as this is a pointer, it could be nil. Logically, I would have said thatNot(HaveValue("whatever")
should pass if the value is a nil, as it doesn't have a value, but it fails right now.For a more concrete example, I would expect the first of these to not fail, where I would expect the second to fail, but they both fail with the same error right now.
Am I misunderstanding?
The workaround I have for now is
The text was updated successfully, but these errors were encountered: