Skip to content

Commit

Permalink
Fix unit tests so that they build and run with SPM, add instructions for
Browse files Browse the repository at this point in the history
SPM to README.md.
  • Loading branch information
mattboran committed Jun 21, 2021
1 parent d2cffb2 commit 653eebc
Show file tree
Hide file tree
Showing 39 changed files with 1,123 additions and 23 deletions.
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
}
107 changes: 90 additions & 17 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// swift-tools-version:5.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

// swift-tools-version:5.3
import PackageDescription

let package = Package(
Expand All @@ -13,32 +11,107 @@ let package = Package(
products: [
.library(
name: "ResponseDetective",
targets: ["ResponseDetective"]
targets: [
"ResponseDetective",
"ResponseDetectiveObjC"
]
)
],
dependencies: [
.package(
url: "https://github.com/Quick/Quick.git",
.exact("3.0.0")
),
.library(
name: "ResponseDetectiveObjC",
targets: ["ResponseDetectiveObjC"]
.package(
url: "https://github.com/Quick/Nimble.git",
.exact("9.0.0")
),
.package(
url: "https://github.com/AliSoftware/OHHTTPStubs.git",
.exact("9.1.0")
)
],
dependencies: [],
targets: [
.target(
name: "ResponseDetective",
dependencies: ["ResponseDetectiveObjC"],
path: "ResponseDetective",
sources: ["Sources/Swift"]
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",
sources: ["Sources/ObjC"]
)
// .testTarget(
// name: "ResponseDetectiveTests",
// dependencies: ["ResponseDetective"],
// path: "ResponseDetective",
// sources: ["Tests"]
// ),
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"
]
),
.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
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ extern const unsigned char ResponseDetectiveVersionString[];

@import Foundation;

#import "ResponseDetective/Sources/ObjC/RDTBodyDeserializer.h"
#import "ResponseDetective/Sources/ObjC/RDTXMLBodyDeserializer.h"
#import "ResponseDetective/Sources/ObjC/RDTHTMLBodyDeserializer.h"
#ifndef SWIFT_PACKAGE
#import <ResponseDetective/RDTBodyDeserializer.h>
#import <ResponseDetective/RDTXMLBodyDeserializer.h>
#import <ResponseDetective/RDTHTMLBodyDeserializer.h>
#else
#import "RDTBodyDeserializer.h"
#import "RDTXMLBodyDeserializer.h"
#import "RDTHTMLBodyDeserializer.h"
#endif
File renamed without changes.
45 changes: 45 additions & 0 deletions ResponseDetective/Tests/Additions/TestBodyDeserializer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// TestBodyDeserializer.swift
//
// Copyright © 2016-2020 Netguru S.A. All rights reserved.
// Licensed under the MIT License.
//

import ResponseDetective
#if SWIFT_PACKAGE
import ResponseDetectiveObjC
#endif

/// A test body deserializer.
internal final class TestBodyDeserializer: NSObject, BodyDeserializer {

/// The closure for deserializing bodies.
let deserializationClosure: @convention(block) (Data) -> String?

/// Creates a general deserializer with given deserialization closure.
///
/// - Parameter deserializationClosure: Implementation of `deserializeBody`.
internal init(deserializationClosure: @escaping @convention(block) (Data) -> String?) {
self.deserializationClosure = deserializationClosure
}

/// Creates a deserializer with fixed deserialized body.
///
/// - Parameter fixedDeserializedBody: A fixed deserialized body.
internal convenience init(fixedDeserializedBody: String?) {
self.init { _ in fixedDeserializedBody }
}

/// Creates a deserializer which deserializes data into plaintext.
internal convenience override init() {
self.init { String(data: $0, encoding: .utf8) as String? }
}

// MARK: Implementation

/// - SeeAlso: BodyDeserializer.deserializeBody(_:)
internal func deserialize(body data: Data) -> String? {
return deserializationClosure(data)
}

}
73 changes: 73 additions & 0 deletions ResponseDetective/Tests/Specs/BufferOutputFacilitySpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// BufferOutputFacilitySpec.swift
//
// Copyright © 2016-2020 Netguru S.A. All rights reserved.
// Licensed under the MIT License.
//

import Foundation
import Nimble
import ResponseDetective
import Quick

internal final class BufferOutputFacilitySpec: QuickSpec {

override func spec() {

describe("BufferOutputFacility") {

let sut = BufferOutputFacility()

it("should buffer request representations") {
let request = RequestRepresentation(
identifier: "0",
method: "GET",
urlString: "http://foo.bar",
headers: [
"X-Foo": "bar",
"X-Baz": "qux",
],
body: nil,
deserializedBody: "lorem ipsum"
)
sut.output(requestRepresentation: request)
expect(sut.requestRepresentations.count).to(beGreaterThanOrEqualTo(1))
}

it("should buffer response representation") {
let response = ResponseRepresentation(
requestIdentifier: "0",
statusCode: 200,
urlString: "http://foo.bar",
headers: [
"X-Bar": "foo",
"X-Qux": "baz",
],
body: nil,
deserializedBody: "dolor sit amet"
)
sut.output(responseRepresentation: response)
expect(sut.responseRepresentations.count).to(beGreaterThanOrEqualTo(1))
}

it("should buffer error representations") {
let error = ErrorRepresentation(
requestIdentifier: "0",
response: nil,
domain: "foo.bar.error",
code: 1234,
reason: "just because",
userInfo: [
"foo": "bar",
"baz": "qux",
]
)
sut.output(errorRepresentation: error)
expect(sut.errorRepresentations.count).to(beGreaterThanOrEqualTo(1))
}

}

}

}
Loading

0 comments on commit 653eebc

Please sign in to comment.