Skip to content

Commit 3c44bcf

Browse files
committed
support path instead of full url, fixes #2
1 parent 419320b commit 3c44bcf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,21 @@ networking.set(mockData: [
174174
),
175175
statusCode: 200, // Int: If omitted, 200 is used
176176
error: nil
177+
),
178+
"/only/an/path": .init(
179+
data: "OVERRIDE", // Can be Data or String
180+
response: .init( // NSURLResponse, Can be nil
181+
url: .init(stringLiteral: "https://wesleydegroot.nl/only/an/path"),
182+
mimeType: "text/html",
183+
expectedContentLength: 8,
184+
textEncodingName: "utf-8"
185+
),
186+
statusCode: 200, // Int: If omitted, 200 is used
187+
error: nil
177188
)
178189
])
179190
```
191+
180192
### Debugging
181193
```swift
182194

Sources/SimpleNetworking/SimpleNetworking.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ open class SimpleNetworking {
9393
/// Set mock url data
9494
/// - Parameter mock: Mock request.
9595
public func set(mockData: [String: SNMock]) {
96-
self.mockData = mockData
96+
var newMockData: [String: SNMock] = [:]
97+
98+
for (url, mock) in mockData {
99+
if let validURL = isURL(url) {
100+
newMockData[validURL.absoluteString] = mock
101+
}
102+
}
103+
104+
self.mockData = newMockData
97105
}
98106

99107
/// Add a cookie to the storage

0 commit comments

Comments
 (0)