I have a method that I want to test that does this:
- (void)openEmailFeedback
{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:@"test@example.com"];
[controller setSubject:@""];
[controller setMessageBody:@"" isHTML:NO];
[self presentViewController:controller animated:YES completion:nil];
}
And I tried testing it with
- (void)testOpenEmailFeedback
{
ViewController *vc = [[ViewController alloc] init];
// Create a partial mock of UIApplication
id mockMailComposeViewController = [OCMockObject mockForClass:[MFMailComposeViewController class]];
[[mockMailComposeViewController expect] setMailComposeDelegate:vc];
[[mockMailComposeViewController expect] setToRecipients:@[@"test@example.com"]];
[[mockMailComposeViewController expect] setSubject:@""];
[[mockMailComposeViewController expect] setMessageBody:@"" isHTML:NO];
[vc openEmailFeedback];
[mockMailComposeViewController verify];
[mockMailComposeViewController stopMocking];
}
But I realized that mockMailComposeViewController is nowhere near being the same variable as the local MFMailComposeViewController *controller that's in the method. Is it possible to some how access a local variable within a method "openEmailFeedback" when testing?