I'm trying to test that my App behaves correctly based on the success or failure of my API call.
when I break point the __block
statements, the block is nil (EXC_BAD_ACCESS
) When I call the userSuccess
block at the bottom, it is also nil. I'm still trying to wrap my head fully around blocks. Thought I had it this time, but obviously not.
Any help greatly appreciated
__block void (^userSuccess)(NSDictionary *data);
__block void (^userFailure)(NSError *error);
__block void (^authSuccess)(NSDictionary *authData);
__block void (^authFailure)(NSError *authError);
beforeAll(^{
[testController stub:@selector(userManager) andReturn:[KWMock nullMockForClass:[CLASS class]]];
[testController stub:@selector(authManager) andReturn:[KWMock nullMockForClass:[CLASS class]]];
[testController.userManager stub:@selector(createWithData:success:failure:) withBlock:^id(NSArray *params) {
userSuccess = [params objectAtIndex:1];
userFailure = [params objectAtIndex:2];
return nil;
}];
[testController.authManager stub:@selector(loginWithEmail:password:disableLaunch:success:failure:) withBlock:^id(NSArray *params) {
authSuccess = [params objectAtIndex:3];
authFailure = [params objectAtIndex:4];
return nil;
}];
});
it(@"should attempt to hit auth after a successful user call", ^{
[[testController.authManager should] receive:@selector(loginWithEmail:password:disableLaunch:success:failure:)];
NSDictionary *responseData = @{};
userSuccess(responseData);
});