문제

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

도움이 되었습니까?

해결책

I think you want

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

Use withMatcher:forArgument: only for primitive arguments.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top