Repository: Moya/Moya
File: Tests/Single+MoyaSpec.swift (Swift)

Code before:
                expect(called).to(beTruthy())
            }

            it("filters out different individual status code") {
                let data = Data()
                let single = Response(statusCode: 43, data: data).asSingle()

                var errored = false
                _ = single.filter(statusCode: 42).subscribe { event in
                    switch event {
                    case .success(let object):
                        fail("called on non-success status code: \(object)")
                    case .error:
                        errored = true
                    }
                }

                expect(errored).to(beTruthy())
            }
        }

        describe("image maping") {
            it("maps data representing an image to an image") {
                let image = Image.testPNGImage(named: "testImage")
                guard let data = image.asJPEGRepresentation(0.75) else {
                    fail("Failed creating Data from Image")
                    return
                }

                let single = Response(statusCode: 200, data: data).asSingle()

                var size: CGSize?
                _ = single.mapImage().subscribe(onSuccess: { image in
                    size = image?.size
                })

                expect(size).to(equal(image.size))
            }

            it("ignores invalid data") {
                let data = Data()
                let single = Response(statusCode: 200, data: data).asSingle()

                var receivedError: MoyaError?
                _ = single.mapImage().subscribe { event in
                    switch event {
                    case .success:
                        fail("next called for invalid data")
                    case .error(let error):
                        receivedError = error as? MoyaError
                    }

Review comment (bug):
I think that `fatalError` might better here, as it is not a failed test, but rather an error in preparation (this one is in few more places as well)

Code after:
                expect(called).to(beTruthy())
            }

            it("filters out different individual status code") {
                let data = Data()
                let single = Response(statusCode: 43, data: data).asSingle()

                var errored = false
                _ = single.filter(statusCode: 42).subscribe { event in
                    switch event {
                    case .success(let object):
                        fail("called on non-success status code: \(object)")
                    case .error:
                        errored = true
                    }
                }

                expect(errored).to(beTruthy())
            }
        }

        describe("image maping") {
            it("maps data representing an image to an image") {
                let image = Image.testPNGImage(named: "testImage")
                guard let data = image.asJPEGRepresentation(0.75) else {
                    fatalError("Failed creating Data from Image")
                }

                let single = Response(statusCode: 200, data: data).asSingle()

                var size: CGSize?
                _ = single.mapImage().subscribe(onSuccess: { image in
                    size = image?.size
                })

                expect(size).to(equal(image.size))
            }

            it("ignores invalid data") {
                let data = Data()
                let single = Response(statusCode: 200, data: data).asSingle()

                var receivedError: MoyaError?
                _ = single.mapImage().subscribe { event in
                    switch event {
                    case .success:
                        fail("next called for invalid data")
                    case .error(let error):
                        receivedError = error as? MoyaError
                    }
                }