Skip to content

Commit 574c0dd

Browse files
author
Sean Henry
committed
Updates documentation for closure support
1 parent a8465fe commit 574c0dd

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Undo is supported for Xcode plugins but you're safer to use source control in th
5656
| Captures invoked property values.|||
5757
| Stubs values for your mocks to return.|||
5858
| Stubs a default value for return values where possible.|||
59-
| Automatically calls closure parameters with stubbed values.|||
59+
| Automatically calls closure parameters with stubbed values.|||
6060
| Supports mocks conforming to one or many protocols.|||
6161
| Handles overloaded method declarations.|||
6262
| Regenerate your mock in one action.|||
@@ -160,6 +160,15 @@ func testMyMethodReturnsTrueWhenSaveWasSuccessful() {
160160
XCTAssertTrue(result)
161161
}
162162
```
163+
Stub the `progress` closure and it is called with the stubbed value:
164+
165+
```
166+
func testStubProgressClosure() {
167+
mockDataStore.stubbedSaveProgressResult = (0.5, ())
168+
object.writeSomeData()
169+
}
170+
```
171+
Closures without arguments are called automatically.
163172

164173
## Disable or remove the plugin
165174

TestProject/DataStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
protocol DataStore {
2-
func save(_ data: Data, to file: URL) -> Bool
2+
func save(_ data: Data, to file: URL, progress: (TimeInterval) -> ()) -> Bool
33
}

TestProject/MockDataStore.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ class MockDataStore: DataStore {
55
var invokedSaveCount = 0
66
var invokedSaveParameters: (data: Data, file: URL)?
77
var invokedSaveParametersList = [(data: Data, file: URL)]()
8+
var stubbedSaveProgressResult: (TimeInterval, Void)?
89
var stubbedSaveResult: Bool! = false
9-
func save(_ data: Data, to file: URL) -> Bool {
10+
func save(_ data: Data, to file: URL, progress: (TimeInterval) -> ()) -> Bool {
1011
invokedSave = true
1112
invokedSaveCount += 1
1213
invokedSaveParameters = (data, file)
1314
invokedSaveParametersList.append((data, file))
15+
if let result = stubbedSaveProgressResult {
16+
progress(result.0)
17+
}
1418
return stubbedSaveResult
1519
}
1620
}
@@ -71,4 +75,9 @@ class ExampleTest: XCTestCase {
7175
let result = object.writeSomeData()
7276
XCTAssertTrue(result)
7377
}
78+
79+
func testStubProgressClosure() {
80+
mockDataStore.stubbedSaveProgressResult = (0.5, ())
81+
object.writeSomeData()
82+
}
7483
}

0 commit comments

Comments
 (0)