我对如何在一个块中使用 Assert 有疑问?
例如:
[someObject postRequestWithBlock:^(BOOL succeeded, NSError *error) {
CFRunLoopRef runLoopRef = CFRunLoopGetCurrent();
CFRunLoopStop(runLoopRef);
GHAssertTrue(succeeded&&!error, @"faile");
}];
CFRunLoopRun();
它必须发送一个异步请求。完成后,我需要断言它是否成功。
但它会崩溃!
我该怎么办?
谢谢!
PS: - (void)testCase { [self prepare];
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]];
__block typeof (&*self) bself = self;
[request setCompletionBlock:^{
[bself notify:kGHUnitWaitStatusSuccess forSelector:@selector(testCase)];
GHAssertTrue(YES, @"faile");
}];
[request setFailedBlock:^{
[bself notify:kGHUnitWaitStatusFailure forSelector:@selector(testCase)];
GHAssertTrue(NO, @"faile");
}];
[request startAsynchronous];
[self waitForStatus:kGHUnitWaitStatusCancelled timeout:15.0];
}