erikdoe / ocmock

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

OCMVerify not working with arguments #326

Closed bilby91 closed 7 years ago

bilby91 commented 7 years ago

Hello!

I'm trying to verify the some methods are being called internally. I want to verify this invocations with a Protocol mock.

QuickSpecBegin(StateSpec)

describe(@"State", ^{

    __block State *state;
    __block Context *contextMock;
    __block id<TestProtocol> bleMock;
    __block Device *device;

    beforeEach(^{
        device = [[Device alloc] init];
        state = [[State alloc] init];
        protoMock = OCMProtocolMock(@protocol(TestProtocol));
        contextMock = OCMPartialMock([[Context alloc] initWithDevice:device delegate:testMock]);
    });

    describe(@"method:", ^{

            beforeEach(^{
                [state handle:Transition withParameters:@{} context:contextMock];
            });

            it(@"connect", ^{
                OCMVerify([protoMock connectToDevice:device]);
            });
        });
 });

When I try to verify the invocation with the real argument it always fails. When I use [OCMArg any] works perfectly. I have checked that the object is the same in both points (internally in the method and in the test).

Any insight on where I can look up to find the issue ?

Thanks in advance!

erikdoe commented 7 years ago

The only thing I can think of is the definition of equality. You write that "the object is the same in both points". How do you determine that they are the same? And is that the same way that OCMock determines whether two objects are the same? The code for the latter is here: https://github.com/erikdoe/ocmock/blob/a60730142ea67229ac08e96fb8005f7eb3600760/Source/OCMock/OCMInvocationMatcher.m#L102-L142

It's likely (but you should double-check) that in your case the code in line 139 is excuted. It would call the isEqual: method of the device object passed when the code is run, and use the device object passed in the verify, as an argument to the isEqual: method. Can you emulate that and see what happens?

bilby91 commented 7 years ago

@erikdoe my bad! I didn't realize that isEquals was overwritten.

Closing the issue. Thanks again @erikdoe .