I'm trying to mock an object that is passed to my SUT. When passed, the SUT registers the mock as observer for some properties. In SUT dealloc, it calls removeObserver
on the mock. This was working just fine with OCMockito 0.23, but when updating to 1.0.0, this test makes OCMockito to get trapped in [HCIsEqual .cxx_destruct]
. Debugging a little bit, lead me to MKTInvocationContainer
method:
- (void)setInvocationForPotentialStubbing:(NSInvocation *)invocation
in which the invocation is told to retain its arguments. Could be a retain cycle?
Furthermore, I've been doing some research and I found several SO answers stating the incompatibility between NSProxy
and KVO:
NSProxy and Key Value Observing
https://stackoverflow.com/a/17457155/2824409
However, I wonder why this was working with OCMockito 0.23 and not now. Any idea?
The solution in my case is to replace the mock with a real object. This works fine, but it is painful to build a whole object for a test suite that barely uses it.
At any case, if KVO is not supported with mocks, I believe this should be documented, and properly handled.
[EDIT]
I found a workaround for this problem.
We are using a custom block based KVO infrastructure, similar to the described here: http://www.mikeash.com/pyblog/key-value-observing-done-right.html. Now, SUT is registering the mock for KVO, passing self
inside a block. I believe self
is being retained somewhere, but it shouldn't be, since it is weakified before the block...
Using the default kvo framework provided by Apple seems to fix this problem. However, I'm still worried about the underlying problem. What changed in OCMockito that makes this fail now?
Anyway, sorry for the trouble and thank you very much.