@@ -5,30 +5,54 @@ private struct StubError: Error, CustomDebugStringConvertible {
5
5
let debugDescription = " StubError "
6
6
}
7
7
8
+ enum TestError : Error , Equatable , CustomDebugStringConvertible {
9
+ case foo, bar
10
+
11
+ var debugDescription : String {
12
+ switch self {
13
+ case . foo:
14
+ return " TestError.foo "
15
+ case . bar:
16
+ return " TestError.bar "
17
+ }
18
+ }
19
+ }
20
+
8
21
final class BeSuccessTest : XCTestCase {
9
22
func testPositiveMatch( ) {
10
23
let result : Result < Int , Error > = . success( 1 )
11
24
expect ( result) . to ( beSuccess ( ) )
12
25
}
13
26
14
- func testPositiveMatchWithValueTesting ( ) {
27
+ func testPositiveMatchWithClosure ( ) {
15
28
let stubValue = 1
16
29
let result : Result < Int , Error > = . success( stubValue)
17
30
expect ( result) . to ( beSuccess { value in
18
31
expect ( value) . to ( equal ( stubValue) )
19
32
} )
20
33
}
21
34
22
- func testNegativeMatch ( ) {
35
+ func testPositiveNegatedMatch ( ) {
23
36
let result : Result < Int , Error > = . failure( StubError ( ) )
24
37
expect ( result) . toNot ( beSuccess ( ) )
25
38
}
26
39
27
- func testExpectationFailureMessage ( ) {
40
+ func testNegativeMatches ( ) {
28
41
failsWithErrorMessage ( " expected to be <success(Int)>, got <failure(StubError)> " ) {
29
42
let result : Result < Int , Error > = . failure( StubError ( ) )
30
43
expect ( result) . to ( beSuccess ( ) )
31
44
}
45
+ failsWithErrorMessage ( " expected to not be <success(Int)>, got <success(1)> " ) {
46
+ let result : Result < Int , Error > = . success( 1 )
47
+ expect ( result) . toNot ( beSuccess ( ) )
48
+ }
49
+
50
+ failsWithErrorMessage ( " expected to be <success(Int)> that satisfies block, got <success(1)> " ) {
51
+ let result : Result < Int , Error > = . success( 1 )
52
+ expect ( result) . to ( beSuccess { _ in
53
+ fail ( )
54
+ } )
55
+ }
32
56
}
33
57
}
34
58
@@ -38,22 +62,43 @@ final class BeFailureTest: XCTestCase {
38
62
expect ( result) . to ( beFailure ( ) )
39
63
}
40
64
41
- func testPositiveMatchWithValueTesting ( ) {
65
+ func testPositiveMatchWithClosure ( ) {
42
66
let result : Result < Int , Error > = . failure( StubError ( ) )
43
67
expect ( result) . to ( beFailure { error in
44
68
expect ( error) . to ( matchError ( StubError . self) )
45
69
} )
70
+
71
+ expect ( Result < Int , TestError > . failure ( . foo) ) . to ( beFailure { error in
72
+ expect ( error) . to ( equal ( . foo) )
73
+ } )
46
74
}
47
75
48
- func testNegativeMatch ( ) {
76
+ func testPositiveNegatedMatch ( ) {
49
77
let result : Result < Int , Error > = . success( 1 )
50
78
expect ( result) . toNot ( beFailure ( ) )
51
79
}
52
80
53
- func testExpectationFailureMessage ( ) {
81
+ func testNegativeMatches ( ) {
54
82
failsWithErrorMessage ( " expected to be <failure(Error)>, got <success(1)> " ) {
55
83
let result : Result < Int , Error > = . success( 1 )
56
84
expect ( result) . to ( beFailure ( ) )
57
85
}
86
+ failsWithErrorMessage ( " expected to not be <failure(Error)>, got <failure(StubError)> " ) {
87
+ let result : Result < Int , Error > = . failure( StubError ( ) )
88
+ expect ( result) . toNot ( beFailure ( ) )
89
+ }
90
+
91
+ failsWithErrorMessage ( " expected to be <failure(Error)> that satisfies block, got <failure(StubError)> " ) {
92
+ let result : Result < Int , Error > = . failure( StubError ( ) )
93
+ expect ( result) . to ( beFailure { _ in
94
+ fail ( )
95
+ } )
96
+ }
97
+ failsWithErrorMessage ( " expected to be <failure(TestError)> that satisfies block, got <failure(TestError.foo)> " ) {
98
+ let result : Result < Int , TestError > = . failure( . foo)
99
+ expect ( result) . to ( beFailure { error in
100
+ expect ( error) . to ( equal ( . bar) )
101
+ } )
102
+ }
58
103
}
59
104
}
0 commit comments