Question

Good day, I'm using OCHamcrest and OCMockito to start my path using TDD methodology, they really cool tools but there's one thing that it seems that I don't understand about mocking a protocol and try to evaluate a parameter.

Considering the example that comes with the code:

- (void)testVerifyWithMatcherForPrimitive
{
    NSMutableArray *mockArray = mock([NSMutableArray class]);

    [mockArray removeObjectAtIndex:2];

    [[verify(mockArray) withMatcher:greaterThan([NSNumber numberWithInt:1]) forArgument:0]
     removeObjectAtIndex:0];    // The 0 is a placeholder, replaced by the matcher
}

It works like expected, but when I try to replicate this with a mock protocol it always pass the tests, for example:

- (void)testFirstParameter
{
    // given
    id<TestProtocol> mockElement = mockProtocol(@protocol(TestProtocol));

    // when
    id toProcess = nil;
    [mockElement process: toProcess];

    // then
    id firstArgumentMatcher = instanceOf([NSArray class]);
    [[verify(mockElement) withMatcher: firstArgumentMatcher forArgument: 0] process: toProcess];
}

In this test I'm trying to test that the argument is instance of an NSArray class, it shouldn't pass. Could you help me to detect what I'm doing wrong?

Thank you very much,

Luis Alejandro

Was it helpful?

Solution

I think you want

[[verify(mockElement) process:instanceOf([NSArray class])];

Use withMatcher:forArgument: only for primitive arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top