lundi 28 décembre 2015

OCMock - Mocking nested blocks

I am testing the following method with OCMock:

- (void)methodToTest {
    [self.someObject doFirstActionWithParam:@"aparam" completion:(void(^)(BOOL success)) {
        if (success) {
            [self.someObject doSecondActionWithParam:@"aparam" completion:(void(^)(BOOL success)) {
                if (success) { [self doSomething]; }
             }];
        }
    }];
}

I have a partial mock for self.someObject.

The doFirstActionWithParam, I am able to set an expectation for. I am also overriding the completion block (via NSInvocation and invoking a YES completion).

However, I am not able to get the call for doSecondActionWithParam method. I also set up expectation for doSomething method. That never comes through.

Any suggestion for an approach to test nested completion blocks?

Aucun commentaire:

Enregistrer un commentaire