erikdoe / ocmock

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

OCMVerify & OCMReject using arguments work w/ PartialMocks but not ClassMocks #327

Closed sen-lu closed 4 years ago

sen-lu commented 7 years ago

Hi,

We're trying to verify that certain internal methods are or are not being called. Despite confirming that the arguments passed in the test & the internal method are the same object in memory, the below test is failing:

- (void)testHandleMessageFromAction {
  Action *action = [[Action alloc] init];
  action.message = [[Message alloc] init];
  id mockController = OCMClassMock([Controller class]);

  OCMStub([mockController showMessage:message fromAction:action]).andDo(nil);
  [controller handleAction:action];
  OCMVerify([mockController showMessage:message fromAction:action]);
  [mockController stopMocking];
}

We also replaced the message and action arguments with [OCMArg any] and the test continued to fail. However, if we replace the mockController with a partial mock, i.e.,

  Controller *controller = [[Controller alloc] init];
  id mockController = OCMPartialMock(controller);

the same test passes. The above behavior also applies to OCMReject tests.

Any thoughts on this behavior? Thanks in advance!

erikdoe commented 7 years ago

In general, please ask questions related to the usage of OCMock on StackOverflow using the ocmock tag.

In particular, there is not enough information to diagnose the issue. Where does the test fail? What is the error message? How is thecontroller instance variable initialised? How would that controller even know about the mock controller to call a message on it?

erikdoe commented 4 years ago

Closing due to inactivity.