Skip to content

Commit

Permalink
Correct usage in readme (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
q231950 authored Oct 3, 2019
1 parent 8879f4c commit b6ec081
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Unit tests use "plain" stubs where each stub only lives for the duration of the

```swift
/// given
let session = StubbornNetwork.stubbed(withConfiguration: .ephemeral) { (stubbedSession) in
let session = StubbornNetwork.makeEphemeralSession({ (stubbedSession) in
stubbedSession.stub(NetworkClient.request, data: self.stubData, response: HTTPURLResponse(), error: nil)
}
})
let networkClient = NetworkClient(urlSession: session)

/// when
Expand Down Expand Up @@ -57,14 +57,10 @@ let urlSession: URLSession
let processInfo = ProcessInfo()

if processInfo.testing == false {
/// Use the standard URLSession when not testing.
urlSession = URLSession(configuration: .ephemeral)
} else {
/// Use a stubbed URLSession when testing.
urlSession = StubbornNetwork.stubbed(withProcessInfo: processInfo, stub: { (stubbedURLSession) in

/// It is possible to record stubs instead of manually stubbing each request.
stubbedURLSession.recordMode = .recording
urlSession = StubbornNetwork.makePersistentSession({ (stubbedURLSession) in
stubbedURLSession.recordMode = .playback
})
}

Expand Down Expand Up @@ -120,12 +116,11 @@ A SwiftUI Preview utilizes **The Stubborn Network** mostly like a cache. You rec

```swift
static var previews: some View {
let urlSession = StubbornNetwork.stubbed(withConfiguration: .persistent(name: "ContentView_Previews", path: "\(ProcessInfo().environment["PROJECT_DIR"] ?? "")/stubs")!) { (session) in
session.recordMode = .playback
}

let networkClient = NetworkClient(urlSession: urlSession)
/// Use the stubbed `networkClient`...
let urlSession = StubbornNetwork.makePersistentSession(withName: "ContentView_Previews", path: "some_path_to/stubs", { (session) in
session.recordMode = .playback
})
let networkClient = NetworkClient(urlSession: urlSession)
/// Use the stubbed `networkClient`...
}
```

Expand Down

0 comments on commit b6ec081

Please sign in to comment.