erikdoe / ocmock

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

Add support for classes blocking mocking. #439

Closed dmaclach closed 3 years ago

dmaclach commented 4 years ago

Certain classes should not be mocked. They may not be able to support being mocked because of implementation details that conflict with how OCMock is implemented. This allows library developers to prevent those classes from being mocked.

erikdoe commented 3 years ago

Merged this with three noteworthy changes: 1) The method to block mocking is a class method and we don't want to check for presence of the protocol. Therefore I have move the declaration from a formal protocol to a category. 2) I was uncomfortable with the double use of nil/reason to signal whether mocking should be blocked and to return a reason. For that reason I changed the signature to return a boolean and the reason in a separate argument. I've also changed the to the "positive", i.e. returning NO means that mocking is not supported. Of course, not implementing the method still implies that mocking is supported. 3) I reverted the removal of the nil object check in the partial mock object class. That wasn't covered anymore as far as I understand.