jonreid / OCMockito

Mockito for Objective-C: creation, verification and stubbing of mock objects
MIT License
991 stars 118 forks source link

Stub singleton weak ref fix #137

Closed igorsales closed 8 years ago

igorsales commented 8 years ago

Jon, I have ran into the issue again, where it intermittently does not work with that mock comparison in the if statement. So, I think comparing pointers ought to reliably work. Let me know if you would like to discuss further. It's happening for some of us, and not for some others (it may depend on the LLVM used).

I think I got a working solution now. The mock comparison was not enough. Sometimes, it was comparing nil == nil, which would be true, but not what we wanted (because self.mock was nullified and the parameter theMock was also nil. I worked around this by creating a 'tag' of the mock, using it's pointer (hence the _mockPtr) ivar. That can be assigned at construction and won't get changed by ARC's weak refs. We are not de-referencing it anywhere, so it's safe. We're just comparing to see if we should unswizzle on dealloc.

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.06%) to 98.42% when pulling 38b7ae7181778b8f65edb13fb207ad6edb915446 on igorsales:stub_singleton_weak_ref_fix into 2ccb1cfb17c99166b9c669713092ebaed7534f0c on jonreid:master.

jonreid commented 8 years ago

I like it when something becomes more understandable - thanks!