AFNetworking/Tests にポッドをインストールしました AFNetworking (2.0.1) をインストールします Expecta (0.2.3) をインストールします OCMock (2.1.1) をインストールします Pods プロジェクトを生成します クライアント プロジェクトを統合します
テストは実行されますが、エラー ブロックが返されることを期待するテストでエラーが発生します...
testThatCancellationOfRequestOperationInvokesFailureCompletionBlock
testThat500StatusCodeInvokesFailureCompletionBlockWithErrorOnFailure
testThatCancellationOfRequestOperationSetsError
デバッグは、エラー ブロックが nil であることを示しています。
テストでは、リクエストをhttps://httpbin.org/status/404 (最初のテスト) または http://httpbin.org/status/500 (2 番目のテスト)に正しく送信しています。httpbin は期待どおりに機能します (http resultcode は、最初のケースでは 404、2 番目のケースでは期待どおり 500 です。
応答にはエラー コード (1 つのテスト ケースでは 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 では nil です。
エラーログは次のとおりです。
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).
引き続き動作しますが、これは新しいバージョンからの見落としかもしれないと考えました。