erikdoe / ocmock

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

Method init invoked twice #300

Closed valeriomazzeo closed 7 years ago

valeriomazzeo commented 8 years ago

OCMStub([OCMPartialMock([MyClass sharedInstance]) myProperty]).andReturn(@(1234));

triggers "** Method init invoked twice on stub recorder. Are you trying to mock the init method? This is currently not supported."

erikdoe commented 8 years ago

So, what happens when you write it as follows?

id mock = OCMPartialMock([MyClass sharedInstance]);
OCMStub([mock myProperty]).andReturn(@1234);

If this also fails, then you'll have to provide the implementation of myProperty, and whatever is called from it. Otherwise it's impossible to see how the recorder gets called twice.

valeriomazzeo commented 8 years ago

My class implements initWithCoder could it be related?

erikdoe commented 8 years ago

It could be. Without a failing example (in code), or at least some code and more information I can only guess, which I don't like doing. ;-)

erikdoe commented 7 years ago

Closing this due to inactivity.

valeriomazzeo commented 7 years ago

sorry @erikdoe, your first suggestion fixed the issue, then I forgot to reply 👍

hanjt commented 6 years ago

@erikdoe My code is OCMStub([class method:mockArgument]).andReturn(YES). It crashed when run. The exception message is [NSException raise:NSInternalInconsistencyException format:@"** Method init invoked twice on stub recorder. Are you trying to mock the init method? This is currently not supported."];