cedarbdd / cedar

BDD-style testing using Objective-C

Home Page:http://groups.google.com/group/cedar-discuss

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Correct nil should equal(nil) checking

PaulTaykalo opened this issue · comments

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]]);

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

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.