0

刚刚在 AFNetworking/Tests 上安装了 pod 安装 AFNetworking (2.0.1) 安装 Expecta (0.2.3) 安装 OCMock (2.1.1) 生成 Pods 项目 集成客户端项目

测试运行,但我在期望返回错误块的测试中遇到错误......

testThatCancellationOfRequestOperationInvokesFailureCompletionBlock
testThat500StatusCodeInvokesFailureCompletionBlockWithErrorOnFailure
testThatCancellationOfRequestOperationSetsError

调试显示错误块为零。

测试正确地将请求发送到https://httpbin.org/status/404(第一次测试)或 http://httpbin.org/status/500 (第二次测试)。httpbin 按预期工作(http 结果代码对于第一种情况是 404,对于第二种情况是 500,如预期的那样。

虽然响应包含错误代码(一个测试用例中的 404,另一个测试用例中的 500),但 AFNetworking 代码不会返回错误对象::

- (void)testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure {
__block NSError *blockError = nil;

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/404" relativeToURL:self.baseURL]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

// AFHTTPOperation currently does not have a default response serializer
[operation setResponseSerializer:[AFHTTPResponseSerializer serializer]];

[operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    blockError = error;
}];

[operation start];
expect([operation isFinished]).will.beTruthy();
expect(blockError).willNot.beNil();
}

expect(blockError).willNot.beNil();blockError 是零。

错误日志是:

Test Suite 'All tests' started at 2013-10-21 18:11:28 +0000
Test Suite 'iOS Tests.xctest' started at 2013-10-21 18:11:28 +0000
Test Suite 'AFHTTPRequestOperationTests' started at 2013-10-21 18:11:28 +0000
Test Case '-[AFHTTPRequestOperationTests testThatOperationPostsDidFinishNotificationWhenFinished]' started.
Test Case '-[AFHTTPRequestOperationTests testThatOperationPostsDidFinishNotificationWhenFinished]' passed (0.001 seconds).
Test Case '-[AFHTTPRequestOperationTests testThatPausedOperationCanBeResumed]' started.
Test Case '-[AFHTTPRequestOperationTests testThatPausedOperationCanBeResumed]' passed (0.000 seconds).
Test Case '-[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure]' started.
2013-10-21 14:11:28.831 xctest[4261:303]   (null)
2013-10-21 14:11:33.837 xctest[4261:303] /Users/onetokadmin/Downloads/AFNetworking-master/Tests/Tests/AFHTTPRequestOperationTests.m:69 expected: not nil/null, got: nil/null
/Users/onetokadmin/Downloads/AFNetworking-master/Tests/Tests/AFHTTPRequestOperationTests.m:69: error: -[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure] : expected: not nil/null, got: nil/null
Test Case '-[AFHTTPRequestOperationTests testThatOperationInvokesFailureCompletionBlockWithErrorOnFailure]' failed (5.362 seconds).

将继续工作,但认为这可能是新版本的疏忽。

4

0 回答 0