@@ -43,7 +43,7 @@ let mock = Mock<[Int]>()
4343mock.expect(matches([any(), matches { $0 > 0 }])) // expects [_, n > 0]
4444mock.record([0, 1]) // succeeds
4545mock.verify() // succeeds
46- mock.record([1, 0]) // fails (fast)
46+ mock.record([1, 0]) // unexpected, fails (fast)
4747```
4848
4949The order of expectations may also be ignored:
@@ -55,7 +55,7 @@ mock.expect(matches([1, 0]))
5555mock.record([1, 0]) // succeeds
5656mock.record([0, 1]) // succeeds
5757mock.verify() // succeeds
58- mock.record([0, 0]) // fails (fast)
58+ mock.record([0, 0]) // unexpected, fails (fast)
5959```
6060
6161### Nice mocks
@@ -66,10 +66,10 @@ Nice mocks allow unexpected interactions while still respecting the order of exp
6666let mock = Mock<[Int?]>(strict: false)
6767mock.expect(matches([some(0)]))
6868mock.expect(matches([some(any())]))
69- mock.record([nil]) // succeeds
70- mock.verify() // fails
71- mock.record([1]) // fails (fast)
69+ mock.record([nil]) // unexpected, ignored
70+ mock.record([1]) // out of order, ignored
7271mock.record([0]) // succeeds
72+ mock.verify() // fails
7373mock.record([1]) // succeeds
7474mock.verify() // succeeds
7575```
@@ -80,6 +80,7 @@ Of course, nice mocks can ignore the order of expectations too:
8080let mock = Mock<[String: Int?]>(strict: false, ordered: false)
8181mock.expect(matches(["zero": some(0)]))
8282mock.expect(matches(["none": none()]))
83+ mock.record(["some": 1]) // unexpected, ignored
8384mock.record(["none": nil]) // succeeds
8485mock.record(["zero": 0]) // succeeds
8586mock.verify() // succeeds
@@ -92,7 +93,7 @@ In addition to normal expectations, nice mocks allow negative expectations to be
9293```swift
9394let mock = Mock<Int>(nice: true)
9495mock.reject(0)
95- mock.record(0) // fails (fast)
96+ mock.record(0) // rejected, fails (fast)
9697```
9798
9899### Verification with delay
@@ -103,7 +104,8 @@ Verification may also be performed with a delay, allowing expectations to be ful
103104let mock = Mock<Int>()
104105mock.expect(1)
105106
106- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1.0 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
107+ let when = dispatch_time(DISPATCH_TIME_NOW, Int64(1.0 * Double(NSEC_PER_SEC)))
108+ dispatch_after(when, dispatch_get_main_queue()) {
107109 mock.record(1) // succeeds
108110}
109111
@@ -116,17 +118,17 @@ Stubs, when invoked, return a value based on their set up behavior, or, if an in
116118
117119```swift
118120let stub = Stub<(Int, Int), Int>()
119- let behavior = stub.on(equals((4 , 3)), returnValue: 9 )
120- stub.on(matches((any(), any()))) { $0.0 + $0.1 }
121- try! stub.invoke((4 , 3)) // returns 9
122- try! stub.invoke((4, 4 )) // returns 8
121+ let behavior = stub.on(equals((2 , 3)), returnValue: 4 )
122+ stub.on(matches((any(), any()))) { x, y in x * y }
123+ try! stub.invoke((2 , 3)) // returns 4
124+ try! stub.invoke((3, 3 )) // returns 9
123125```
124126
125127Behavior may also be disposed:
126128
127129```swift
128130behavior.dispose()
129- try! stub.invoke((4 , 3)) // returns 7
131+ try! stub.invoke((2 , 3)) // returns 6
130132```
131133
132134## Example
0 commit comments