Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] SPM testing! (+ some other minor updates) #1896

Merged
merged 10 commits into from
Sep 2, 2019
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github "Alamofire/Alamofire" "5.0.0-beta.7"
github "AliSoftware/OHHTTPStubs" "8.0.0"
github "Quick/Nimble" "v8.0.1"
github "Quick/Nimble" "v8.0.2"
github "Quick/Quick" "v2.1.0"
github "ReactiveCocoa/ReactiveSwift" "6.0.0"
github "ReactiveCocoa/ReactiveSwift" "6.1.0"
github "ReactiveX/RxSwift" "5.0.1"
58 changes: 33 additions & 25 deletions Moya.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
83B0E400A7562256224CB7FF /* AccessTokenPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC115388D44D0DB7A753E9BB /* AccessTokenPlugin.swift */; };
85850A4122CF5AB50089E731 /* NimbleHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85850A4022CF5AB50089E731 /* NimbleHelpers.swift */; };
85B2DBBC221C69620098F59A /* PropertyListEncoding.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85B2DBBB221C69620098F59A /* PropertyListEncoding.swift */; };
85D5277A2302BEF30093E9C1 /* TestImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85D527792302BEF30093E9C1 /* TestImage.swift */; };
85F6042E22A018BB00063320 /* RequestTypeWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85F6042D22A018BB00063320 /* RequestTypeWrapper.swift */; };
8995DF740A59721AA79F5B43 /* MoyaProvider+ReactiveSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = C841AA621AEC61FAEA0CA019 /* MoyaProvider+ReactiveSpec.swift */; };
9854C1DBF14818CCA76AEC7F /* MoyaProvider+Internal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 225C397C03E17F7DFBCA2848 /* MoyaProvider+Internal.swift */; };
Expand All @@ -75,7 +76,6 @@
B5A7124CF285D8EC7F89C1AD /* CredentialsPlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884642F58B074C95261DCA86 /* CredentialsPlugin.swift */; };
B950CAA84C0656EB11E316FB /* MultiTargetSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D11E4BE1D5112E6972AD09F /* MultiTargetSpec.swift */; };
BA5EFFB8EE468F6BCA15480C /* Moya.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 559D567FD0DA37D6CC98FF92 /* Moya.framework */; };
BAFB3C28D3BF17C52FDA8FE4 /* testImage.png in Resources */ = {isa = PBXBuildFile; fileRef = CA93F1BAD55FF95EDE17EE61 /* testImage.png */; };
BEAA605B30BE7651BA5C61A4 /* Plugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A693AF0E88E83E91A47A99 /* Plugin.swift */; };
C1B5E2325B210232599B0D1A /* ErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F112022D8F42844A7D5CB5C /* ErrorTests.swift */; };
CCB85FCA228B3D1800AAB253 /* Moya.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 559D567FD0DA37D6CC98FF92 /* Moya.framework */; };
Expand Down Expand Up @@ -193,6 +193,7 @@
851FFE6DC58E873408D0E8E7 /* MoyaProvider.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MoyaProvider.swift; sourceTree = "<group>"; };
85850A4022CF5AB50089E731 /* NimbleHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NimbleHelpers.swift; sourceTree = "<group>"; };
85B2DBBB221C69620098F59A /* PropertyListEncoding.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PropertyListEncoding.swift; sourceTree = "<group>"; };
85D527792302BEF30093E9C1 /* TestImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestImage.swift; sourceTree = "<group>"; };
85F6042D22A018BB00063320 /* RequestTypeWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTypeWrapper.swift; sourceTree = "<group>"; };
86F3C0EA472C23E786E23CE9 /* Image.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = "<group>"; };
8736BEE85376471D7CB1E0ED /* Observable+Response.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "Observable+Response.swift"; sourceTree = "<group>"; };
Expand All @@ -205,7 +206,6 @@
B1F68927EA26EBDB45E82C8C /* MoyaProviderSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = MoyaProviderSpec.swift; sourceTree = "<group>"; };
C79C5F376B4A2C3F70051980 /* Error+MoyaSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "Error+MoyaSpec.swift"; sourceTree = "<group>"; };
C841AA621AEC61FAEA0CA019 /* MoyaProvider+ReactiveSpec.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "MoyaProvider+ReactiveSpec.swift"; sourceTree = "<group>"; };
CA93F1BAD55FF95EDE17EE61 /* testImage.png */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = image.png; path = testImage.png; sourceTree = "<group>"; };
CC115388D44D0DB7A753E9BB /* AccessTokenPlugin.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AccessTokenPlugin.swift; sourceTree = "<group>"; };
D38525FE207BE148B17084F3 /* Moya.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = Moya.h; sourceTree = "<group>"; };
D48555FB39336D99F8365F5E /* MoyaProvider+Rx.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "MoyaProvider+Rx.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -280,28 +280,7 @@
1952C4A00E2EF89FFE965603 /* Tests */ = {
isa = PBXGroup;
children = (
31BAAD7EC02607A52AD3EF1E /* AccessTokenPluginSpec.swift */,
1F24393220125F8200C9D813 /* EndpointClosureSpec.swift */,
E825A32256FC030B8BA2684D /* EndpointSpec.swift */,
C79C5F376B4A2C3F70051980 /* Error+MoyaSpec.swift */,
7F112022D8F42844A7D5CB5C /* ErrorTests.swift */,
819334FE5D32EFB82599D482 /* MethodSpec.swift */,
C841AA621AEC61FAEA0CA019 /* MoyaProvider+ReactiveSpec.swift */,
4C7A20CC38EB5A0221E6EA34 /* MoyaProvider+RxSpec.swift */,
82E52DC541FD052ABA625D2A /* MoyaProviderIntegrationTests.swift */,
B1F68927EA26EBDB45E82C8C /* MoyaProviderSpec.swift */,
369649DCA3D957F2F9D8053A /* MultipartFormDataSpec.swift */,
7D11E4BE1D5112E6972AD09F /* MultiTargetSpec.swift */,
832781077A551E1F86E5F2D4 /* NetworkLoggerPluginSpec.swift */,
461DEED329CE157E412CBCE0 /* Observable+MoyaSpec.swift */,
78A2D3981F44BACD00C9E122 /* RxTestHelpers.swift */,
F1AFAFEA29CDFABC559F0BE2 /* SignalProducer+MoyaSpec.swift */,
78A2D39A1F44D45100C9E122 /* Single+MoyaSpec.swift */,
4650771638DBA96BDE28F11B /* TestHelpers.swift */,
85B2DBBB221C69620098F59A /* PropertyListEncoding.swift */,
CA93F1BAD55FF95EDE17EE61 /* testImage.png */,
DCACC7B19F3FFC2DEE74E07B /* TestPlugin.swift */,
85850A4022CF5AB50089E731 /* NimbleHelpers.swift */,
85D527782302B4CC0093E9C1 /* MoyaTests */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -420,6 +399,35 @@
path = Plugins;
sourceTree = "<group>";
};
85D527782302B4CC0093E9C1 /* MoyaTests */ = {
isa = PBXGroup;
children = (
31BAAD7EC02607A52AD3EF1E /* AccessTokenPluginSpec.swift */,
1F24393220125F8200C9D813 /* EndpointClosureSpec.swift */,
E825A32256FC030B8BA2684D /* EndpointSpec.swift */,
C79C5F376B4A2C3F70051980 /* Error+MoyaSpec.swift */,
7F112022D8F42844A7D5CB5C /* ErrorTests.swift */,
819334FE5D32EFB82599D482 /* MethodSpec.swift */,
C841AA621AEC61FAEA0CA019 /* MoyaProvider+ReactiveSpec.swift */,
4C7A20CC38EB5A0221E6EA34 /* MoyaProvider+RxSpec.swift */,
82E52DC541FD052ABA625D2A /* MoyaProviderIntegrationTests.swift */,
B1F68927EA26EBDB45E82C8C /* MoyaProviderSpec.swift */,
369649DCA3D957F2F9D8053A /* MultipartFormDataSpec.swift */,
7D11E4BE1D5112E6972AD09F /* MultiTargetSpec.swift */,
832781077A551E1F86E5F2D4 /* NetworkLoggerPluginSpec.swift */,
461DEED329CE157E412CBCE0 /* Observable+MoyaSpec.swift */,
78A2D3981F44BACD00C9E122 /* RxTestHelpers.swift */,
F1AFAFEA29CDFABC559F0BE2 /* SignalProducer+MoyaSpec.swift */,
78A2D39A1F44D45100C9E122 /* Single+MoyaSpec.swift */,
4650771638DBA96BDE28F11B /* TestHelpers.swift */,
85B2DBBB221C69620098F59A /* PropertyListEncoding.swift */,
85D527792302BEF30093E9C1 /* TestImage.swift */,
DCACC7B19F3FFC2DEE74E07B /* TestPlugin.swift */,
85850A4022CF5AB50089E731 /* NimbleHelpers.swift */,
);
path = MoyaTests;
sourceTree = "<group>";
};
94621FEF4A2A1BFCE4BA36D0 /* RxMoya */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -689,7 +697,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
BAFB3C28D3BF17C52FDA8FE4 /* testImage.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -909,6 +916,7 @@
1F24393320125F8200C9D813 /* EndpointClosureSpec.swift in Sources */,
4033070748A57EB4A0040DB1 /* NetworkLoggerPluginSpec.swift in Sources */,
85850A4122CF5AB50089E731 /* NimbleHelpers.swift in Sources */,
85D5277A2302BEF30093E9C1 /* TestImage.swift in Sources */,
E9B54EFE4EF4A96444BA76AA /* Observable+MoyaSpec.swift in Sources */,
8995DF740A59721AA79F5B43 /* MoyaProvider+ReactiveSpec.swift in Sources */,
58F73370045D6F1FBF73FC82 /* MoyaProvider+RxSpec.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
"version": "8.0.2"
}
},
{
"package": "OHHTTPStubs",
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs.git",
"state": {
"branch": "feature/spm-support",
"revision": "fda9902f8c5c4170c6914d7dc845174e8c75bf92",
"version": null
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
Expand Down
46 changes: 30 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import PackageDescription

let package = Package(
name: "Moya",
platforms: [
.macOS(.v10_12),
.iOS(.v10),
.tvOS(.v10),
.watchOS(.v3)
],
products: [
.library(name: "Moya", targets: ["Moya"]),
.library(name: "ReactiveMoya", targets: ["ReactiveMoya"]),
Expand All @@ -11,34 +17,42 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", .exact("5.0.0-beta.7")),
.package(url: "https://github.com/ReactiveCocoa/ReactiveSwift.git", .upToNextMajor(from: ("6.0.0"))),
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0"))
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/Quick/Quick.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "8.0.0")),
.package(url: "https://github.com/AliSoftware/OHHTTPStubs.git", .branch("feature/spm-support")),
],
targets: [
.target(
name: "Moya",
dependencies: [
"Alamofire"],
exclude: [
"Tests",
"Sources/Supporting Files",
"Examples"]),
"Alamofire"
]
),
.target(
name: "ReactiveMoya",
dependencies: [
"Moya",
"ReactiveSwift"],
exclude: [
"Tests",
"Sources/Supporting Files",
"Examples"]),
"ReactiveSwift"
]
),
.target(
name: "RxMoya",
dependencies: [
"Moya",
"RxSwift"],
exclude: [
"Tests",
"Sources/Supporting Files",
"Examples"])
"RxSwift"
]
),
.testTarget(
name: "MoyaTests",
dependencies: [
"Moya",
"RxMoya",
"ReactiveMoya",
"Quick",
"Nimble",
"OHHTTPStubsSwift"
]
)
]
)
2 changes: 2 additions & 0 deletions Sources/Moya/RequestTypeWrapper.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

// Workaround for new asynchronous handling of Alamofire's request creation.
struct RequestTypeWrapper: RequestType {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Quick
import Nimble
import Moya
import Foundation

final class AccessTokenPluginSpec: QuickSpec {
struct TestTarget: TargetType, AccessTokenAuthorizable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Quick
import Moya
import Nimble
import Foundation

final class NonUpdatingRequestEndpointConfiguration: QuickConfiguration {
override static func configure(_ configuration: Configuration) {
Expand Down Expand Up @@ -345,6 +346,7 @@ final class EndpointSpec: QuickSpec {
}
}

#if !SWIFT_PACKAGE
context("when task is .requestCompositeParameters") {
it("throws an error when bodyEncoding is an URLEncoding.queryString") {
endpoint = endpoint.replacing(task: .requestCompositeParameters(bodyParameters: [:], bodyEncoding: URLEncoding.queryString, urlParameters: [:]))
Expand All @@ -361,6 +363,7 @@ final class EndpointSpec: QuickSpec {
expect { _ = try? endpoint.urlRequest() }.toNot(throwAssertion())
}
}
#endif
}
}
}
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions Tests/ErrorTests.swift → Tests/MoyaTests/ErrorTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Quick
import Nimble
@testable
import Moya
import XCTest

@testable import Moya

final class ErrorTests: QuickSpec {
override func spec() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Quick
import Nimble
import ReactiveSwift

#if canImport(OHHTTPStubs)
import OHHTTPStubs
#elseif canImport(OHHTTPStubsSwift)
import OHHTTPStubsCore
import OHHTTPStubsSwift
#endif

@testable import Moya
@testable import ReactiveMoya
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Quick
import Nimble
import RxSwift

#if canImport(OHHTTPStubs)
import OHHTTPStubs
#elseif canImport(OHHTTPStubsSwift)
import OHHTTPStubsCore
import OHHTTPStubsSwift
#endif

@testable import Moya
@testable import RxMoya
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Quick
import Nimble
import Foundation

#if canImport(OHHTTPStubs)
import OHHTTPStubs
#elseif canImport(OHHTTPStubsSwift)
import OHHTTPStubsCore
import OHHTTPStubsSwift
#endif

@testable import Moya
@testable import ReactiveMoya
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
import Quick
import Nimble
import Foundation

#if canImport(OHHTTPStubs)
import OHHTTPStubs
#elseif canImport(OHHTTPStubsSwift)
import OHHTTPStubsCore
import OHHTTPStubsSwift
#endif

@testable import Moya

final class MoyaProviderSpec: QuickSpec {
Expand Down Expand Up @@ -884,7 +891,7 @@ final class MoyaProviderSpec: QuickSpec {
}

it("tracks progress of request") {
let url = Bundle(for: MoyaProviderSpec.self).url(forResource: "testImage", withExtension: "png")!
let url = testImageUrl
let target: HTTPBin = .upload(file: url)

var progressObjects: [Progress?] = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Quick
import Nimble
import Foundation

@testable import Moya

final class MultiTargetSpec: QuickSpec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Quick
import Nimble
import Foundation

@testable import Moya

final class MultiPartFormData: QuickSpec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Quick
import Nimble
import Moya
import Foundation
import enum Alamofire.AFError

final class NetworkLoggerPluginSpec: QuickSpec {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Quick
import Moya
import RxSwift
import Nimble
import Foundation

final class ObservableMoyaSpec: QuickSpec {
override func spec() {
Expand Down Expand Up @@ -190,7 +191,7 @@ final class ObservableMoyaSpec: QuickSpec {

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

let observable = Response(statusCode: 200, data: data).asObservable()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Alamofire
import Foundation

internal struct PropertyListEncoding: ParameterEncoding {

Expand Down
File renamed without changes.
Loading