The problem with putting your assertions in the blocks is that you wouldn't know if neither block were called. This is what we do:
__block BOOL done = NO;
[classUnderTest doSomethingWithResultBlock:^(BOOL success) {
done = YES;
} errorBlock:^(BOOL success) {
// should not be called
expect(NO).to.beTruthy();
}];
while (!done) [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
The drawback is that if the success block is never called, the tests will hang in the while loop. You could avoid that by adding a timeout:
NSDate *startTime = [NSDate date];
__block BOOL done = NO;
[classUnderTest doSomethingWithResultBlock:^(BOOL success) {
done = YES;
} errorBlock:^(BOOL success) {
// should not be called
expect(NO).to.beTruthy();
}];
while (!done && [startTime timeIntervalSinceNow] > -30) [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
// make sure it didn't time out
expect(done).to.beTruthy();