所以我需要测试是否NSNotification
发布了 a 。我尝试了以下代码来监视参数。
[[NSNotificationCenter defaultCenter] stub:@selector(postNotification:)];
__block KWCaptureSpy *notificationSpy = [[NSNotificationCenter
defaultCenter] captureArgument:@selector(postNotification:) atIndex:0];
[[theValue(notificationSpy.argument.name) should] equal:theValue(SOME_NOTIFICATION)];
但是这个问题是因为它是异步的,所以在测试之前并不总是捕获参数。我也无法添加shouldEventually
notificationSpy.argument.name,因为它会NSInternalConsistencyException
在捕获之前访问参数。
我也试过了,
[[SOME_NOTIFICATION should] bePosted];
也失败了。