I am using a UIAlertView+Blocks with a tapBlock from https://github.com/ryanmaxwell/UIAlertView-Blocks.
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Title"
message:@"Please press a button."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tapBlock = ^(UIAlertView *alertView, NSInteger buttonIndex) {
if (buttonIndex == alertView.firstOtherButtonIndex) {
// things happen here
}
};
[alert show];
I can mock the alert view with OCMock and test that it has popped up.
id mockAlertView = [OCMockObject mockForClass:[UIAlertView class]];
[[[mockAlertView stub] andReturn:mockAlertView] alloc];
(void)[[[mockAlertView expect] andReturn:mockAlertView]
initWithTitle:@"Title"
message:@"Please press a button."
delegate:OCMOCK_ANY
cancelButtonTitle:OCMOCK_ANY
otherButtonTitles:OCMOCK_ANY, nil];
[[mockAlertView expect] setTapBlock:OCMOCK_ANY]; // this is not what I want
[[mockAlertView expect] show];
// cause the alert view to show
[mockAlertView verify];
[mockAlertView stopMocking];
But I'd also want to delegate the tapBlock to its original implementation. Sadly it doesn't look like I can make a partial mock here.
How can I solve that? In the end I want to test that the popup appears and if the user clicks on the right button things that are inside of that block happen.