0

Hi I had a problem when testing a method that send a object message when I Run, the test failed and show me this error:

failed: caught "NSInvalidArgumentException", "*** -[NSProxy doesNotRecognizeSelector:sendMessage:] called!"

this is my test method :

- (void)testSendingRequests
 {
        MNRequest *request = [MNRequest requestWithType:@"AUselessType"
                                                    content:@"AUselessContent"
                                                   delegate:nil
                                                    timeOut:10
                                                   userInfo:nil];

            MNMessage * message = mockClass([MNMessage class]);
            [given([mockMsgCenter sendMessage:message]) willDo:^id(NSInvocation *invocation) {
                // Mock implementation goes here
        }
        NSNumber *identificationNumber = [center sendRequest:request];
        verify(mockMsgCenter);
        // some other code
  }

this is a screen for the error: enter image description here

Walid Sassi
  • 185
  • 2
  • 16

1 Answers1

0

this the solution of the problem

MNMessage * message = mockClass([MNMessage class]);
    [given([mockMsgCenter sendMessage:message]) willDo:^id(NSInvocation *invocation) {
        // Mock implementation goes here
        NSArray *args = [invocation mkt_arguments];
        MNMessage * msg = args[0];
        MNPackagedRequest *pkgRequest = (MNPackagedRequest *)[args[0] content];
        BOOL c1 = [msg.type isEqualToString:MNRequestMessageType];
        BOOL c2 = [[pkgRequest type] isEqualToString:@"AUselessType"];
        BOOL c3 = [(NSString *)[pkgRequest content] isEqualToString:@"AUselessContent"];
        BOOL c4 = [[msg content] isEqual:pkgRequest];
        BOOL c5 = [msg guaranteedDelivery];
        BOOL c6 = ([msg ttl] == request.timeOut);
        return @(c1 && c2 && c3 && c4 && c5 && c6);
    }];
     NSNumber *identificationNumber = [center sendRequest:request];
     verify(mockMsgCenter);
Walid Sassi
  • 185
  • 2
  • 16