I have a view controller that adds itself as an observer of UIApplicationDidBecomeActiveNotification during viewDidLoad. I'd like to verify that this happens but I don't want the test to care what specific selector the view controller registers for the event.
Currently my test looks something like this:
- (void)testRegistersForApplicationDidBecomeActiveEvent
{
//given
MyViewController *sut = [MyViewController new];
NSNotificationCenter* mockNotificationCenter = mock([NSNotificationCenter class);
//when
[sut view];
//then
[verify([mockNotificationCenter]) addObserver:sut
selector:anything()
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
...but passing "anything()" for the selector gives a compiler error: "Implicit conversion of an Objective-C pointer to 'SEL' is disallowed with ARC".
I can make the test work if I pass "@selector(applicationDidBecomeActive:)" instead of anything. That is the exact selector the view controller uses. But I'd prefer the test not have that much knowledge of the specific implementation, if possible.