Last active
August 29, 2015 14:24
-
-
Save thiagolioy/f57606cbb53db8f9ccf3 to your computer and use it in GitHub Desktop.
Testing Mocking blocks response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__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]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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