objective c - OCMock is not cleaning up stubbed class methods -


i'm trying use ocmock mock out internal class dependencies (e.g. class uses nsmutabledata , verifying against mock nsmutabledata). i'm mocking factory methods return mock objects.

as far can tell mock objects not cleaning class method mocks, or cleaning them partially. having pretty adverse effects on unrelated tests may end invoking same class methods.

a short example i've been able repro locally illustrate:

id data1 = [nsmutabledata data];    // new instance id data2 = [nsmutabledata data];    // new instance  // mock +data , have return data1 id mock = [ocmockobject mockforclass:[nsmutabledata class]]; [[[[mock stub] classmethod] andreturn:data1] data];  id foo = [nsmutabledata data];  // foo == data1 ok that's  [mock stopmocking]; mock = nil;                     // using arc no explicit -release  id bar = [nsmutabledata data];  // bar == data1, wait what? shouldn't new? 

i've found problem worse if mock +new. last line create bar blows either bad string hash or stack overflow (i'm not sure how consistently 1 or other, i've seen both).

i realize there's ways around this. inject nsmutabledata instance class, feels overkill since it's not hard dependency. have instance method on class creates nsmutabledata , partially mock class instead inject mock. that's fine know why particular case doesn't work. mocking internal dependencies quite bit easier if stub out factory methods!

this issue not limited particular ns classes (i'm aware of limitations around mocking nsstring example) can repro above issue 1 of own classes easily.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -