Convert disableMocking and stopMocking to stopAllMocks #143
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Jon,
Here's what I was thinking around the
stopAllMocks()
functionality I talked about in #141The idea is that OCMockito will keep a reference to any mocks objects it creates, and when
stopAllMocks()
is called, it will take care of the intricacies of disabling all mocks, then stopping all mocks, thus freeing the test writer from having to understand the different memory management and crash scenarios that can manifest when doing this manually.As such, I've also removed
disableMocking()
andstopMocking()
from the public API. Testers now just need to make sure they callstopAllMocks()
from thetearDown
method (or equivalent) of their test.Changes in behaviour
Before this change, if a test didn't call stopMocking() on a mock, it may or may not have leaked, depending on the way the mock was used. Now, if a test doesn't call stopAllMocks(), it will leak memory, both from the mocks and all of their message arguments. Likewise, before this change, when setting the mock to nil, deallocation may or may not have run. Now, if stopAllMocks() has been called, deallocation is guaranteed to run when the mock is set to nil.
Other behaviour
Verifying mocks after
stopAllMocks()
has been called is undefined. As I understand it, this will never fail regardless of how the mock was used prior tostopAllMocks()
. This is no different from the current verify behaviour afterstopMocking()
is called on a mock though.Let me know what you think. Hopefully, this will lead to a simpler and more understandable API (with respect to memory management at least).
Also, just to be extra clear - this is an API-breaking change.
Thanks!
Cer