Repository: Moya/Moya
File: Tests/MoyaProviderSpec.swift (Swift)

Code before:
                            }
                            expect(validStatusCodes).toNot(contain(response!.statusCode))
                        }
                    }
                }
            }
            context("response contains valid status code") {
                it("returns a success case") {
                    let endpointClosure = { (target: GitHub) -> Endpoint in
                        return Endpoint(
                            url: URL(target: target).absoluteString,
                            sampleResponseClosure: { .networkResponse(200, target.sampleData) },
                            method: target.method,
                            task: target.task,
                            httpHeaderFields: target.headers
                        )
                    }
                    stubbedProvider = MoyaProvider<GitHub>(endpointClosure: endpointClosure, stubClosure: MoyaProvider.immediatelyStub)
                    let validStatusCodes = GitHub.zen.validationType.statusCodes
                    stubbedProvider.request(.zen) { result in
                        switch result {
                        case .success(let response):
                            expect(validStatusCodes).toNot(beEmpty())
                            expect(validStatusCodes).to(contain(response.statusCode))
                        case .failure(let error):
                            guard case let MoyaError.underlying(_, response) = error else {
                                fatalError("Expected MoyaError.underlying for validation failure.")
                            }
                            expect(validStatusCodes).toNot(contain(response!.statusCode))
                        }
                    }
                }
            }
        }
    }
}


Review comment (bug):
here a `failure` case is probably a failed test, as we expect only `success` case, right? and similar in the above test with the `success case`?

Code after:
                            }
                            done()
                        }
                    }

                    expect(receivedResponse).to(beNil())
                    expect(receivedError).toNot(beNil())
                }
            }

            context("response contains valid status code") {
                it("returns a response") {
                    let endpointClosure = { (target: GitHub) -> Endpoint in
                        return Endpoint(
                            url: URL(target: target).absoluteString,
                            sampleResponseClosure: { .networkResponse(200, target.sampleData) },
                            method: target.method,
                            task: target.task,
                            httpHeaderFields: target.headers
                        )
                    }

                    stubbedProvider = MoyaProvider<GitHub>(endpointClosure: endpointClosure, stubClosure: MoyaProvider.immediatelyStub)

                    var receivedError: Error?
                    var receivedResponse: Response?

                    waitUntil { done in
                        stubbedProvider.request(.zen) { result in
                            switch result {
                            case .success(let response):
                                receivedResponse = response
                            case .failure(let error):
                                receivedError = error
                            }
                            done()
                        }
                    }

                    expect(receivedResponse).toNot(beNil())
                    expect(receivedError).to(beNil())
                    expect(GitHub.zen.validationType.statusCodes).to(contain(receivedResponse!.statusCode))
                }
            }
        }
    }
}