erikdoe / ocmock

Mock objects for Objective-C
http://ocmock.org
Apache License 2.0
2.16k stars 606 forks source link

Selectively Ignoring Object Arguments #347

Open alanterranova opened 7 years ago

alanterranova commented 7 years ago

Hi Erik,

Now that OCMock retains arguments passed to mocks, I’m unable to test dealloc logic for objects whose references are retained by mocks.

Is it possible to enable "legacy" behavior on a per-mock basis, such as adding a method on OCMockObject that skips retention ("noRetainObjectArgs") or releases arguments ("releaseObjectArgs")? Happy to contribute if either seems reasonable.

Thanks,

Alan

erikdoe commented 7 years ago

I understand the issue. However, this seems to be quite a niche use case and, at the same time, this would make some already complex logic inside OCMock even more complex and it would require changes to the API.

For your cases could you not just send a release to the objects in question from your test code? I know it feels "asymmetric" but it's also pragmatic.

alanterranova commented 7 years ago

In some cases I can nil the mocks in question, but not mocks that need to be verified. Explicitly releasing the objects under test is disallowed in ARC. That's where having the ability to release (or simply not retain) arguments would be useful.