Skip to content

Instantly share code, notes, and snippets.

@thiagolioy
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagolioy/f57606cbb53db8f9ccf3 to your computer and use it in GitHub Desktop.
Save thiagolioy/f57606cbb53db8f9ccf3 to your computer and use it in GitHub Desktop.
Testing Mocking blocks response
__block HomeViewController *vc;
beforeAll(^{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *controller = [mainStoryboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
vc = (HomeViewController *)(controller);
[vc view];
});
it(@"should proceedToLogin with check multilple has only one account", ^{
id controllerMock = [OCMockObject partialMockForObject:vc];
[[controllerMock expect] proceedToLogin];
[[[controllerMock expect] andReturnValue:OCMOCK_VALUE(NO)] hasAccounts];
[vc checkAccountsList];
[controllerMock verify];
[controllerMock stopMocking];
});
describe(@"fetchKeyboard", ^{
it(@"shouldFetchKeyboard successBlock", ^{
//Prepare
id managerMock = [OCMockObject niceMockForClass:IPFApiClient.class];
[[[managerMock expect] andDo:^(NSInvocation *invocation) {
void (^successBlock)(IPFContaCliente *contaClient);
//First 2 params of any invocation in objc are self and _cmd
[invocation getArgument:&successBlock atIndex:3];
IPFContaCliente *client = [IPFContaCliente new];
client.nomeCliente = @"Thiago Lioy";
successBlock(client);
}] requestKeyboardForAccount:[OCMArg any]
successBlock:[OCMArg any]
failureBlock:[OCMArg any]];
id classMock = OCMClassMock(IPFApiClient.class);
OCMStub(ClassMethod([classMock sharedClient])).andReturn(managerMock);
//Act
[vc fetchKeyboard];
//Assert
expect(vc.contaCliente.nomeCliente).to.equal("Thiago Lioy");
});
it(@"shouldFetchKeyboard failureBlock", ^{
//Prepare
vc.contaCliente = nil;
id managerMock = [OCMockObject niceMockForClass:IPFApiClient.class];
[[[managerMock expect] andDo:^(NSInvocation *invocation) {
void (^failureBlock)(AFHTTPRequestOperation *operation, NSError *error);
//First 2 params of any invocation in objc are self and _cmd
[invocation getArgument:&failureBlock atIndex:4];
NSError *anError = [[NSError alloc] initWithDomain:@"NovoErro" code:2 userInfo:nil];
failureBlock(nil,anError);
}] requestKeyboardForAccount:[OCMArg any]
successBlock:[OCMArg any]
failureBlock:[OCMArg any]];
id classMock = OCMClassMock(IPFApiClient.class);
OCMStub(ClassMethod([classMock sharedClient])).andReturn(managerMock);
//Act
[vc fetchKeyboard];
//Assert
expect(vc.contaCliente).to.beNil();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment