On my app delegate class I have a simple property
@property (strong, nonatomic) LoginAppDelegate *loginAppDelegate;
I then offload the app delegate like functionality for all login views here so I can keep my main app delegate class small (ish)
Then on the login app delegate I have a method to push a view controller on the main navigation controller
- (void)launchSomeOtherViewController {}
The painful part is when I’m inside a view controller that invokes this “launch” method
- (void)callBackAfterSomeHttpMethodLetsSay
{
[self.appDelegate.loginAppDelegate launchSomeOtherViewController];
}
When I try to mock this out it appears my stub on the app delegate isn’t correct
- (void)testCallBackWithSignupTokenInvokesLaunchCompleteSignupViewControllerWithToken
{
id mockLoginAppDelegate = [OCMockObject mockForClass:[LoginAppDelegate class]];
id mockAppDelegate = [OCMockObject mockForClass:[AppDelegate class]];
[[[mockAppDelegate stub] andReturn:mockLoginAppDelegate] loginAppDelegate];
[[mockLoginAppDelegate expect] launchSomeOtherViewController];
[self.sut callBackAfterSomeHttpMethodLetsSay];
[mockLoginAppDelegate verify];
}
The error when I run this via ocunit is the usual “expected method was not invoked”
So my question is related to the way I’m stubbing this -can I do a stub that returns the login mock as I have or do I need to reach into the getter manually?
It looks like you’re not making your
mockAppDelegatevisible to the class under test. Try adding: