I'm using Kiwi to write the tests for my app.
I wrote tests to test against my API. I was guided by this example in the documentation for testing asynchronous calls: https://github.com/allending/Kiwi/wiki/Asynchronous-Testing
My tests are long, so I made a simplified version of my issue:
describe(@"My Class Name", ^{
context(@"populate", ^{
it(@"download the content", ^{
__block NSString *testResponseObject = nil;
__block NSError *testError = nil;
MyClient *apiClient = [MyClient sharedClient];
NSMutableURLRequest *request = [apiClient requestWithMethod:@"DELETE" path:@"my/path" parameters:nil];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
testResponseObject = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
testError = error;
}];
[apiClient enqueueHTTPRequestOperation:operation];
[[expectFutureValue(testResponseObject) shouldEventuallyBeforeTimingOutAfter(100)] equal:@"Expected Content"];
[[expectFutureValue(testError) shouldEventuallyBeforeTimingOutAfter(100)] shouldBeNil];
});
});
});
The thing is that if everything works as expected & the operation succeeds the failure block never gets called & instead of nil for NSError I get KWAsyncVerifier.
I'm guessing that's because Kiwi waits for the block where testError is referenced to be executed which never happens & that's why I have KWAsyncVerifier stuck into testError instead of nil.
Is there any alternative how to test this out?