Skip to content
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

Correct nil should equal(nil) checking #100

Closed
PaulTaykalo opened this issue Aug 7, 2013 · 2 comments
Closed

Correct nil should equal(nil) checking #100

PaulTaykalo opened this issue Aug 7, 2013 · 2 comments

Comments

@PaulTaykalo
Copy link
Contributor

Case 1

nil should equal(nil)
Result : Succeeds, since nil has integer type

Case 2

obj.stringPropery = nil
obj2.stringPropery = nil
...
obj.stringPropery should equal(obj2.stringPropery)

Result : Fails, since Equal comparator
https://github.com/pivotal/cedar/blob/master/Source/Headers/Matchers/Comparators/CompareEqual.h#L9
will transform it [nil isEqual:nil]

Proposed solution

Add by-reference check for objects

return [actualValueId nonretainedObjectValue] == [expectedValueId nonretainedObjectValue] || [[actualValueId nonretainedObjectValue] isEqual:[expectedValueId nonretainedObjectValue]];

OR

return ([actualValueId nonretainedObjectValue] == nil && [expectedValueId nonretainedObjectValue] == nil) || 
       ([[actualValueId nonretainedObjectValue] isEqual:[expectedValueId nonretainedObjectValue]]);
@idoru
Copy link
Contributor

idoru commented Aug 7, 2013

Thanks for picking this up and reporting it. I've just pushed a fix for this to master @c7ae8bc9

@idoru idoru closed this as completed Aug 7, 2013
@idoru
Copy link
Contributor

idoru commented Aug 15, 2013

We ended up reverting this change. The old behavior is more effective at driving out implementations with fewer tests. If you explicitly expect values to be nil then there is always the be_nil matcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants