Skip to content

Instantly share code, notes, and snippets.

@ecgreb
Last active December 17, 2015 03:19
Show Gist options
  • Save ecgreb/5542029 to your computer and use it in GitHub Desktop.
Save ecgreb/5542029 to your computer and use it in GitHub Desktop.
@implementation HelloTDDViewControllerTests {
HelloTDDViewController *viewController;
}
- (void)setUp {
viewController = [[HelloTDDViewController alloc] init];
}
//...
- (void)testOnButtonClickNotifiesDelegate {
MockHelloTDDViewControllerDelegate *delegate =
[[MockHelloTDDViewControllerDelegate alloc] init];
viewController.delegate = delegate;
[viewController onButtonClick:nil];
BOOL result = delegate.buttonWasClicked;
STAssertTrue(result,
@"View controller should notify delegate on button click.");
}
- (void)testOnButtonClickPassesNameToDelegate {
MockHelloTDDViewControllerDelegate *delegate =
[[MockHelloTDDViewControllerDelegate alloc] init];
viewController.delegate = delegate;
UITextField *textField = [[UITextField alloc] init];
textField.text = @"First Last";
viewController.nameField = textField;
[viewController onButtonClick:nil];
STAssertEqualObjects(delegate.lastNameSent, @"First Last",
@"View controller should pass name to delegate.");
}
//...
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment