I've got a KVO scenario test like this:
- (void)testObserverCalled
{
__block BOOL executed = NO;
[[RACObserve(model, dateText) skip:1] subscribeNext:^(id x) {
executed = YES;
}];
[model setDate:[NSDate date]];
XCTAssertTrue(executed);
}
目前我使用一个已执行的BOOL值来测试观察者块是否被调用,是否有更好的方法,例如在测试函数结束之前必须调用的断言?
像这样:
XCAssertCalledBeforeFunctionReturn()
为了让我的代码更改为:
- (void)testObserverCalled
{
[[RACObserve(model, dateText) skip:1] subscribeNext:^(id x) {
XCAssertCalledBeforeFunctionReturn()
}];
[model setDate:[NSDate date]];
}