erikdoe/ocmock — pull request #45 by carllindberg (2013-08-11 21:49:07+00:00)
Title: When using partial mocks, override the -class method to return the original class

When using partial mocks, override the -class method to return the original class. This lets things like [NSBundle bundleForClass:[self class]] to continue to work as expected when mocked.

KVO does this as well with its subclasses.

I did keep one bit of existing behavior which is technically not correct; we mock the result of [self class] rather than the actual runtime class, which is not always the same. In particular, this feature is what stops KVO notifications from being sent, as the private class which KVO creates is effectively removed. However, if we subclassed the KVO class instead, we would get crashes as the KVO overrides are sensitive to the "isa" value being correct from its perspective. It is probably possible to make most things work with KVO but it is a fair bit more involved. I did add a couple of test cases to show current behavior with KVO; adding an observer to an already-mocked object is fine and should work, but mocking a class which already has KVO observers basically disables KVO (but does not crash).

This branch is off of master; if you choose to merge #44 it will have a couple of small conflicts.