Skip to content

Commit

Permalink
Move Combine code to separate CombineMoya target
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxDesiatov committed Apr 1, 2020
1 parent 5644997 commit 7ccbf9d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let package = Package(
],
products: [
.library(name: "Moya", targets: ["Moya"]),
.library(name: "CombineMoya", targets: ["CombineMoya"]),
.library(name: "ReactiveMoya", targets: ["ReactiveMoya"]),
.library(name: "RxMoya", targets: ["RxMoya"])
],
Expand All @@ -26,9 +27,10 @@ let package = Package(
],
targets: [
.target(name: "Moya", dependencies: ["Alamofire"]),
.target(name: "CombineMoya", dependencies: ["Moya"]),
.target(name: "ReactiveMoya", dependencies: ["Moya", "ReactiveSwift"]),
.target(name: "RxMoya", dependencies: ["Moya", "RxSwift"]),
.testTarget(name: "MoyaTests", dependencies: ["Moya", "RxMoya", "ReactiveMoya", "Quick", "Nimble", "OHHTTPStubsSwift"]) // dev
.testTarget(name: "MoyaTests", dependencies: ["Moya", "CombineMoya", "RxMoya", "ReactiveMoya", "Quick", "Nimble", "OHHTTPStubsSwift"]) // dev
]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Foundation
import Combine
import Moya

#if canImport(UIKit)
import UIKit.UIImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import Foundation
import Combine
import Moya

@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public extension MoyaProvider {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(Combine)

import Combine
import Moya

// This should be already provided in Combine, but it's not.
// Ideally we would like to remove it, in favor of a framework-provided solution, ASAP.
Expand All @@ -12,9 +13,9 @@ internal class MoyaPublisher<Output>: Publisher {

private class Subscription: Combine.Subscription {

private let cancellable: Cancellable?
private let cancellable: Moya.Cancellable?

init(subscriber: AnySubscriber<Output, MoyaError>, callback: @escaping (AnySubscriber<Output, MoyaError>) -> Cancellable?) {
init(subscriber: AnySubscriber<Output, MoyaError>, callback: @escaping (AnySubscriber<Output, MoyaError>) -> Moya.Cancellable?) {
self.cancellable = callback(subscriber)
}

Expand All @@ -27,9 +28,9 @@ internal class MoyaPublisher<Output>: Publisher {
}
}

private let callback: (AnySubscriber<Output, MoyaError>) -> Cancellable?
private let callback: (AnySubscriber<Output, MoyaError>) -> Moya.Cancellable?

init(callback: @escaping (AnySubscriber<Output, MoyaError>) -> Cancellable?) {
init(callback: @escaping (AnySubscriber<Output, MoyaError>) -> Moya.Cancellable?) {
self.callback = callback
}

Expand Down
17 changes: 9 additions & 8 deletions Tests/MoyaTests/MoyaProvider+CombineSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Quick
import Nimble
import Combine
import CombineMoya

#if canImport(OHHTTPStubs)
import OHHTTPStubs
Expand Down Expand Up @@ -135,8 +136,8 @@ final class MoyaProviderCombineSpec: QuickSpec {
var provider: MoyaProvider<GitHub>!

beforeEach {
OHHTTPStubs.stubRequests(passingTest: {$0.url!.path == "/zen"}, withStubResponse: { _ in
return OHHTTPStubsResponse(data: GitHub.zen.sampleData, statusCode: 200, headers: nil)
HTTPStubs.stubRequests(passingTest: {$0.url!.path == "/zen"}, withStubResponse: { _ in
return HTTPStubsResponse(data: GitHub.zen.sampleData, statusCode: 200, headers: nil)
})
provider = MoyaProvider<GitHub>(trackInflights: true)
}
Expand Down Expand Up @@ -196,8 +197,8 @@ final class MoyaProviderCombineSpec: QuickSpec {
try? FileManager.default.removeItem(at: file)

//`responseTime(-4)` equals to 1000 bytes at a time. The sample data is 4000 bytes.
OHHTTPStubs.stubRequests(passingTest: {$0.url!.path.hasSuffix("logo_github.png")}, withStubResponse: { _ in
return OHHTTPStubsResponse(data: GitHubUserContent.downloadMoyaWebContent("logo_github.png").sampleData, statusCode: 200, headers: nil).responseTime(-4)
HTTPStubs.stubRequests(passingTest: {$0.url!.path.hasSuffix("logo_github.png")}, withStubResponse: { _ in
return HTTPStubsResponse(data: GitHubUserContent.downloadMoyaWebContent("logo_github.png").sampleData, statusCode: 200, headers: nil).responseTime(-4)
})
provider = MoyaProvider<GitHubUserContent>()
}
Expand Down Expand Up @@ -240,16 +241,16 @@ final class MoyaProviderCombineSpec: QuickSpec {
}

describe("a custom callback queue") {
var stubDescriptor: OHHTTPStubsDescriptor!
var stubDescriptor: HTTPStubsDescriptor!

beforeEach {
stubDescriptor = OHHTTPStubs.stubRequests(passingTest: {$0.url!.path == "/zen"}, withStubResponse: { _ in
return OHHTTPStubsResponse(data: GitHub.zen.sampleData, statusCode: 200, headers: nil)
stubDescriptor = HTTPStubs.stubRequests(passingTest: {$0.url!.path == "/zen"}, withStubResponse: { _ in
return HTTPStubsResponse(data: GitHub.zen.sampleData, statusCode: 200, headers: nil)
})
}

afterEach {
OHHTTPStubs.removeStub(stubDescriptor)
HTTPStubs.removeStub(stubDescriptor)
}

describe("a provider with a predefined callback queue") {
Expand Down

0 comments on commit 7ccbf9d

Please sign in to comment.