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

Add Swift Package Manager support #64

Merged
merged 3 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ DerivedData

Pods
Carthage
.build
.swiftpm
52 changes: 52 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "682841464136f8c66e04afe5dbd01ab51a3a56f2",
"version": "2.1.0"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "02b7a39a99c4da27abe03cab2053a9034379639f",
"version": "2.0.0"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "e491a6731307bb23783bf664d003be9b2fa59ab5",
"version": "9.0.0"
}
},
{
"package": "OHHTTPStubs",
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs.git",
"state": {
"branch": null,
"revision": "12f19662426d0434d6c330c6974d53e2eb10ecd9",
"version": "9.1.0"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "0038bcbab4292f3b028632556507c124e5ba69f3",
"version": "3.0.0"
}
}
]
},
"version": 1
}
121 changes: 121 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "ResponseDetective",
platforms: [
.iOS(.v8),
.macOS(.v10_10),
.tvOS(.v9)
],
products: [
.library(
name: "ResponseDetective",
targets: [
"ResponseDetective",
"ResponseDetectiveObjC"
]
)
],
dependencies: [
.package(
url: "https://github.com/Quick/Quick.git",
.exact("3.0.0")
),
.package(
url: "https://github.com/Quick/Nimble.git",
.exact("9.0.0")
),
.package(
url: "https://github.com/AliSoftware/OHHTTPStubs.git",
.exact("9.1.0")
)
],
targets: [
.target(
name: "ResponseDetective",
dependencies: ["ResponseDetectiveObjC"],
path: "ResponseDetective",
exclude: [
"Configuration",
"Resources",
"Tests",
"include",
"Sources/RDTHTMLBodyDeserializer.h",
"Sources/RDTXMLBodyDeserializer.h",
"Sources/ResponseDetective.h",
"Sources/RDTHTMLBodyDeserializer.m",
"Sources/RDTBodyDeserializer.h",
"Sources/RDTXMLBodyDeserializer.m"
],
sources: [
"Sources/ResponseRepresentation.swift",
"Sources/ErrorRepresentation.swift",
"Sources/ResponseDetective.swift",
"Sources/BufferOutputFacility.swift",
"Sources/ConsoleOutputFacility.swift",
"Sources/URLEncodedBodyDeserializer.swift",
"Sources/PlaintextBodyDeserializer.swift",
"Sources/ImageBodyDeserializer.swift",
"Sources/JSONBodyDeserializer.swift",
"Sources/Dictionary.swift",
"Sources/URLProtocol.swift",
"Sources/OutputFacility.swift",
"Sources/RequestRepresentation.swift"
]
),
.target(
name: "ResponseDetectiveObjC",
dependencies: [],
path: "ResponseDetective",
exclude: [
"Configuration",
"Resources",
"Tests",
"Sources/ResponseRepresentation.swift",
"Sources/ErrorRepresentation.swift",
"Sources/ResponseDetective.swift",
"Sources/BufferOutputFacility.swift",
"Sources/ConsoleOutputFacility.swift",
"Sources/URLEncodedBodyDeserializer.swift",
"Sources/PlaintextBodyDeserializer.swift",
"Sources/ImageBodyDeserializer.swift",
"Sources/JSONBodyDeserializer.swift",
"Sources/Dictionary.swift",
"Sources/URLProtocol.swift",
"Sources/OutputFacility.swift",
"Sources/RequestRepresentation.swift"
],
sources: [
"Sources/RDTHTMLBodyDeserializer.h",
"Sources/RDTXMLBodyDeserializer.h",
"Sources/ResponseDetective.h",
"Sources/RDTHTMLBodyDeserializer.m",
"Sources/RDTBodyDeserializer.h",
"Sources/RDTXMLBodyDeserializer.m"
],
cSettings: [
.headerSearchPath("ResponseDetective/Sources"),
.headerSearchPath("ResponseDetective")
]
),
.testTarget(
name: "ResponseDetectiveTests",
dependencies: [
"ResponseDetective",
"ResponseDetectiveObjC",
"Quick",
"Nimble",
"OHHTTPStubs"
],
path: "ResponseDetective",
exclude: [
"Configuration",
"Resources",
"Sources",
"include",
],
sources: ["Tests"]
),
]
)
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
![](https://img.shields.io/github/release/netguru/ResponseDetective.svg)
![](https://img.shields.io/badge/carthage-compatible-green.svg)
![](https://img.shields.io/badge/cocoapods-compatible-green.svg)
![](https://img.shields.io/badge/spm-compatible-green.svg)
![](https://img.shields.io/badge/license-MIT-blue.svg)

**ResponseDetective** is a non-intrusive framework for intercepting any outgoing requests and incoming responses between your app and your server for debugging purposes.
Expand Down Expand Up @@ -129,6 +130,10 @@ use_frameworks!
pod 'ResponseDetective', '~> {version}'
```

### Swift Package Manager

If you're using [Swift Package Manager](https://github.com/apple/swift-package-manager), add this repository to the Swift Packages in your project settings.

### Local

To install the test dependencies or to build ResponseDetective itself, do not run `carthage` directly. It can't handle the Apple Silicon architectures introduced in Xcode 12. Instead, run it through the `carthage.sh` script:
Expand All @@ -137,6 +142,12 @@ To install the test dependencies or to build ResponseDetective itself, do not ru
$ ./carthage.sh bootstrap
```

Alternatively, you can run the tests locally using Swift Package Manager with the following command:

```bash
$ swift test
```

## About

This project was made with ♡ by [Netguru](https://netguru.com).
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Sources/ImageBodyDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#elseif os(OSX)
import AppKit
#endif
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// Deserializes image bodies.
@objc(RDTImageBodyDeserializer) public final class ImageBodyDeserializer: NSObject, BodyDeserializer {
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Sources/JSONBodyDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import Foundation
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// Deserializes JSON bodies.
@objc(RDTJSONBodyDeserializer) public final class JSONBodyDeserializer: NSObject, BodyDeserializer {
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Sources/PlaintextBodyDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import Foundation
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// Deserializes plaintext bodies.
@objc(RDTPlaintextBodyDeserializer) public final class PlaintextBodyDeserializer: NSObject, BodyDeserializer {
Expand Down
6 changes: 3 additions & 3 deletions ResponseDetective/Sources/ResponseDetective.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ extern const unsigned char ResponseDetectiveVersionString[];

@import Foundation;

#import <ResponseDetective/RDTBodyDeserializer.h>
#import <ResponseDetective/RDTXMLBodyDeserializer.h>
#import <ResponseDetective/RDTHTMLBodyDeserializer.h>
#import "RDTBodyDeserializer.h"
#import "RDTXMLBodyDeserializer.h"
#import "RDTHTMLBodyDeserializer.h"
3 changes: 3 additions & 0 deletions ResponseDetective/Sources/ResponseDetective.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import Foundation
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// ResponseDetective configuration cluster class that defines the behavior
/// of request interception and logging.
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Sources/URLEncodedBodyDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import Foundation
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// Deserializes URL-encoded bodies.
@objc(RDTURLEncodedBodyDeserializer) public final class URLEncodedBodyDeserializer: NSObject, BodyDeserializer {
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Tests/Additions/TestBodyDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//

import ResponseDetective
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// A test body deserializer.
internal final class TestBodyDeserializer: NSObject, BodyDeserializer {
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Tests/Specs/HTMLBodyDeserializerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import Foundation
import Nimble
import ResponseDetective
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif
import Quick

internal final class HTMLBodyDeserializerSpec: QuickSpec {
Expand Down
13 changes: 9 additions & 4 deletions ResponseDetective/Tests/Specs/ResponseDetectiveSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ internal final class ResponseDetectiveSpec: QuickSpec {
describe("ResponseDetective") {

beforeSuite {
stub(condition: isHost("httpbin.org")) { _ in
HTTPStubs.stubRequests { request in
return request.url?.host == "httpbin.org"
} withStubResponse: { _ in
return HTTPStubsResponse(data: Data(), statusCode: 200, headers: nil)
}
}
Expand Down Expand Up @@ -150,10 +152,11 @@ internal final class ResponseDetectiveSpec: QuickSpec {

describe("request interception") {

let buffer = BufferOutputFacility()
var buffer: BufferOutputFacility!
let configuration = URLSessionConfiguration.default

beforeEach {
buffer = BufferOutputFacility()
ResponseDetective.outputFacility = buffer
ResponseDetective.registerBodyDeserializer(TestBodyDeserializer(), forContentType: "*/*")
ResponseDetective.enable(inConfiguration: configuration)
Expand Down Expand Up @@ -192,10 +195,11 @@ internal final class ResponseDetectiveSpec: QuickSpec {

describe("response interception") {

let buffer = BufferOutputFacility()
var buffer: BufferOutputFacility!
let configuration = URLSessionConfiguration.default

beforeEach {
buffer = BufferOutputFacility()
ResponseDetective.outputFacility = buffer
ResponseDetective.registerBodyDeserializer(TestBodyDeserializer(), forContentType: "*/*")
ResponseDetective.enable(inConfiguration: configuration)
Expand Down Expand Up @@ -228,10 +232,11 @@ internal final class ResponseDetectiveSpec: QuickSpec {

describe("error interception") {

let buffer = BufferOutputFacility()
var buffer: BufferOutputFacility!
let configuration = URLSessionConfiguration.default

beforeEach {
buffer = BufferOutputFacility()
ResponseDetective.outputFacility = buffer
ResponseDetective.registerBodyDeserializer(TestBodyDeserializer(), forContentType: "*/*")
ResponseDetective.enable(inConfiguration: configuration)
Expand Down
3 changes: 3 additions & 0 deletions ResponseDetective/Tests/Specs/XMLBodyDeserializerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import Foundation
import Nimble
import ResponseDetective
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif
import Quick

internal final class XMLBodyDeserializerSpec: QuickSpec {
Expand Down
1 change: 1 addition & 0 deletions ResponseDetective/include/RDTBodyDeserializer.h
1 change: 1 addition & 0 deletions ResponseDetective/include/RDTHTMLBodyDeserializer.h
1 change: 1 addition & 0 deletions ResponseDetective/include/RDTXMLBodyDeserializer.h
1 change: 1 addition & 0 deletions ResponseDetective/include/ResponseDetective.h