erikdoe / ocmock

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

When a second mock is created for the same class, dispose of the dynamically created subclass for the first mock. #352

Closed davidsansome closed 6 years ago

davidsansome commented 6 years ago

Previously that first dynamically created subclass was kept around forever, and if accessed somehow (for example by enumerating objc_getClassList) would always raise NSInternalInconsistencyException.

pletoss commented 6 years ago

Hey. So I had an issue and noticed this as well. When will this PR get into a new version on cocoapods ?

erikdoe commented 6 years ago

I had planned to wait for the outcome of #339 to include in the next minor release. It's been taken a while, I know.

swhitty commented 6 years ago

This PR created a regression, If 2 partial mocks are created with the same underlying Class type, then the first mock stops forwarding @selectors to the real object.

p1.name = @"Person 1";
p2.name = @"Person 2";
Person *mock1 = OCMPartialMock(p1);
mock1.name == @"Person 1"
Person *mock2 = OCMPartialMock(p2);
mock2.name == @"Person 2"
mock1.name == nil //😱
erikdoe commented 6 years ago

Could you check whether the fix I just committed works for you? The new tests introduced in this PR still pass, but the class pair is disposed a little later; not when the second mock takes over but when stopMocking is called on the first mock.