Correct nil should equal(nil) checking
PaulTaykalo opened this issue · 2 comments
PaulTaykalo commented
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 commented
Thanks for picking this up and reporting it. I've just pushed a fix for this to master @c7ae8bc9
idoru commented
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.