forked from Brightify/Cuckoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFailTest.swift
133 lines (102 loc) · 3.98 KB
/
FailTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// FailTest.swift
// Cuckoo
//
// Created by Filip Dolnik on 06.07.16.
// Copyright © 2016 Brightify. All rights reserved.
//
import XCTest
@testable import Cuckoo
class FailTest: XCTestCase {
func testMissingInvocation() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
verify(mock).noReturn()
}
XCTAssertEqual(error, "Wanted 1 times but not invoked.")
}
func testNoInvocation2Wanted() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
mock.noReturn()
verify(mock, times(2)).noReturn()
}
XCTAssertEqual(error, "Wanted 2 times but invoked 1 times.")
}
func testInvocationNeverWanted() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
mock.noReturn()
verify(mock, never()).noReturn()
}
XCTAssertEqual(error, "Wanted never but invoked 1 times.")
}
func testInvocationAtLeast2Wanted() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
mock.noReturn()
verify(mock, atLeast(2)).noReturn()
}
XCTAssertEqual(error, "Wanted at least 2 times but invoked 1 times.")
}
func test2InvocationAtMost1Wanted() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
mock.noReturn()
mock.noReturn()
verify(mock, atMost(1)).noReturn()
}
XCTAssertEqual(error, "Wanted at most 1 times but invoked 2 times.")
}
func testCallMatcherOr() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
verify(mock, times(1).or(times(2))).noReturn()
}
XCTAssertEqual(error, "Wanted either 1 times or 2 times but not invoked.")
}
func testCallMatcherAnd() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass()
stub(mock) { mock in
when(mock.noReturn()).thenDoNothing()
}
verify(mock, atLeast(1).and(atMost(2))).noReturn()
}
XCTAssertEqual(error, "Wanted both at least 1 times and at most 2 times but not invoked.")
}
func testVerifyNoMoreInteractionsFail() {
let error = TestUtils.catchCuckooFail {
let mock = MockTestedClass().withEnabledSuperclassSpy()
mock.withOptionalClosure("a", closure: nil)
mock.noReturn()
_ = mock.count(characters: "b")
let _ = mock.readWriteProperty
mock.readWriteProperty = 1
mock.withOptionalClosure("c", closure: { _ in })
verifyNoMoreInteractions(mock)
}
XCTAssertEqual(error, ["No more interactions wanted but some found:",
"1. withOptionalClosure(\"a\", nil)",
"2. noReturn()",
"3. count(\"b\")",
"4. readWriteProperty#get",
"5. readWriteProperty#set(1)",
"6. withOptionalClosure(\"c\", Optional((Function)))"].joined(separator: "\n"))
}
}