Skip to content

Commit 519d337

Browse files
committed
Avoid to directly reference AssertionCheckerBuilder by adding an indirection through AssertionChecker
1 parent b13c72c commit 519d337

File tree

2 files changed

+154
-104
lines changed

2 files changed

+154
-104
lines changed

source/Buoy-Assertions-Tests/AssertionCheckerBuilderTest.class.st

Lines changed: 136 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@ I'm a test case for Assertion Checker Builder
44
Class {
55
#name : #AssertionCheckerBuilderTest,
66
#superclass : #TestCase,
7-
#instVars : [
8-
'checkerBuilder'
9-
],
10-
#category : 'Buoy-Assertions-Tests'
7+
#category : #'Buoy-Assertions-Tests'
118
}
129

13-
{ #category : #initialization }
14-
AssertionCheckerBuilderTest >> setUp [
15-
16-
checkerBuilder := AssertionCheckerBuilder new
17-
]
18-
1910
{ #category : #tests }
2011
AssertionCheckerBuilderTest >> testConditionalChecking [
2112

@@ -24,16 +15,22 @@ AssertionCheckerBuilderTest >> testConditionalChecking [
2415
explanation := 'A row count must be positive'.
2516
rowCount := -15.
2617

27-
checkerBuilder
28-
checking: [ :asserter | asserter refuse: [ rowCount isNil ] because: [ self fail ] onSuccess: [ :successAsserter | successAsserter enforce: [ rowCount positive ] because: [ explanation ] ] ].
29-
3018
self
31-
should: [ checkerBuilder buildAndCheck ]
19+
should: [
20+
AssertionChecker check: [ :asserter |
21+
asserter
22+
refuse: [ rowCount isNil ]
23+
because: [ self fail ]
24+
onSuccess: [ :successAsserter |
25+
successAsserter enforce: [ rowCount positive ] because: [ explanation ] ]
26+
]
27+
]
3228
raise: AssertionFailed
33-
withExceptionDo: [ :exception |
29+
withExceptionDo: [ :exception |
3430
self
3531
assert: exception messageText equals: explanation;
36-
assertCollection: exception failures hasSameElements: {explanation} ]
32+
assertCollection: exception failures hasSameElements: { explanation }
33+
]
3734
]
3835

3936
{ #category : #tests }
@@ -44,15 +41,22 @@ AssertionCheckerBuilderTest >> testConditionalCheckingWhenFirstConditionFails [
4441
explanation := 'A row count must be positive'.
4542
rowCount := -15.
4643

47-
checkerBuilder checking: [ :asserter | asserter enforce: [ rowCount positive ] because: explanation onSuccess: [ :successAsserter | self fail ] ].
4844

4945
self
50-
should: [ checkerBuilder buildAndCheck ]
46+
should: [
47+
AssertionChecker check: [ :asserter |
48+
asserter
49+
enforce: [ rowCount positive ]
50+
because: explanation
51+
onSuccess: [ :successAsserter | self fail ]
52+
]
53+
]
5154
raise: AssertionFailed
52-
withExceptionDo: [ :exception |
55+
withExceptionDo: [ :exception |
5356
self
5457
assert: exception messageText equals: explanation;
55-
assertCollection: exception failures hasSameElements: {explanation} ]
58+
assertCollection: exception failures hasSameElements: { explanation }
59+
]
5660
]
5761

5862
{ #category : #tests }
@@ -61,21 +65,24 @@ AssertionCheckerBuilderTest >> testFailFast [
6165
| mathFailureExplanation |
6266

6367
mathFailureExplanation := 'An obvious math error'.
64-
checkerBuilder
65-
failFast;
66-
checking: [ :asserter |
67-
asserter
68-
enforce: [ 2 > 3 ] because: mathFailureExplanation;
69-
enforce: [ self fail ] because: [ self fail ];
70-
enforce: [ self fail ] because: [ self fail ] ].
7168

7269
self
73-
should: [ checkerBuilder buildAndCheck ]
70+
should: [
71+
AssertionChecker
72+
check: [ :asserter |
73+
asserter
74+
enforce: [ 2 > 3 ] because: mathFailureExplanation;
75+
enforce: [ self fail ] because: [ self fail ];
76+
enforce: [ self fail ] because: [ self fail ]
77+
]
78+
configuredBy: #failFast
79+
]
7480
raise: AssertionFailed
75-
withExceptionDo: [ :exception |
81+
withExceptionDo: [ :exception |
7682
self
7783
assert: exception messageText equals: mathFailureExplanation;
78-
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
84+
assertCollection: exception failures hasSameElements: { mathFailureExplanation }
85+
]
7986
]
8087

8188
{ #category : #tests }
@@ -84,22 +91,28 @@ AssertionCheckerBuilderTest >> testFailFastConfiguringErrorToRaise [
8491
| mathFailureExplanation |
8592

8693
mathFailureExplanation := 'An obvious math error'.
87-
checkerBuilder
88-
failFast;
89-
raising: InstanceCreationFailed;
90-
checking: [ :asserter |
91-
asserter
92-
enforce: [ 2 > 3 ] because: mathFailureExplanation;
93-
enforce: [ self fail ] because: [ self fail ];
94-
enforce: [ self fail ] because: [ self fail ] ].
9594

9695
self
97-
should: [ checkerBuilder buildAndCheck ]
96+
should: [
97+
AssertionChecker
98+
check: [ :asserter |
99+
asserter
100+
enforce: [ 2 > 3 ] because: mathFailureExplanation;
101+
enforce: [ self fail ] because: [ self fail ];
102+
enforce: [ self fail ] because: [ self fail ]
103+
]
104+
configuredBy: [ :checker |
105+
checker
106+
failFast;
107+
raising: InstanceCreationFailed
108+
]
109+
]
98110
raise: InstanceCreationFailed
99-
withExceptionDo: [ :exception |
111+
withExceptionDo: [ :exception |
100112
self
101113
assert: exception messageText equals: mathFailureExplanation;
102-
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
114+
assertCollection: exception failures hasSameElements: { mathFailureExplanation }
115+
]
103116
]
104117

105118
{ #category : #tests }
@@ -108,21 +121,27 @@ AssertionCheckerBuilderTest >> testFailFastInConditional [
108121
| mathFailureExplanation |
109122

110123
mathFailureExplanation := 'An obvious math error'.
111-
checkerBuilder
112-
failFast;
113-
checking: [ :asserter |
114-
asserter
115-
enforce: [ true ] because: [ self fail ] onSuccess: [ :successAsserter | successAsserter enforce: [ false ] because: mathFailureExplanation ];
116-
enforce: [ self fail ] because: [ self fail ];
117-
enforce: [ self fail ] because: [ self fail ] ].
118124

119125
self
120-
should: [ checkerBuilder buildAndCheck ]
126+
should: [
127+
AssertionChecker
128+
check: [ :asserter |
129+
asserter
130+
enforce: [ true ]
131+
because: [ self fail ]
132+
onSuccess: [ :successAsserter |
133+
successAsserter enforce: [ false ] because: mathFailureExplanation ];
134+
enforce: [ self fail ] because: [ self fail ];
135+
enforce: [ self fail ] because: [ self fail ]
136+
]
137+
configuredBy: #failFast
138+
]
121139
raise: AssertionFailed
122-
withExceptionDo: [ :exception |
140+
withExceptionDo: [ :exception |
123141
self
124142
assert: exception messageText equals: mathFailureExplanation;
125-
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
143+
assertCollection: exception failures hasSameElements: { mathFailureExplanation }
144+
]
126145
]
127146

128147
{ #category : #tests }
@@ -131,21 +150,24 @@ AssertionCheckerBuilderTest >> testFailFastPassingSomeConditions [
131150
| failureExplanation |
132151

133152
failureExplanation := 'An obvious math error'.
134-
checkerBuilder
135-
failFast;
136-
checking: [ :asserter |
137-
asserter
138-
enforce: [ true ] because: [ self fail ];
139-
enforce: [ false ] because: failureExplanation;
140-
enforce: [ self fail ] because: [ self fail ] ].
141153

142154
self
143-
should: [ checkerBuilder buildAndCheck ]
155+
should: [
156+
AssertionChecker
157+
check: [ :asserter |
158+
asserter
159+
enforce: [ true ] because: [ self fail ];
160+
enforce: [ false ] because: failureExplanation;
161+
enforce: [ self fail ] because: [ self fail ]
162+
]
163+
configuredBy: #failFast
164+
]
144165
raise: AssertionFailed
145-
withExceptionDo: [ :exception |
166+
withExceptionDo: [ :exception |
146167
self
147168
assert: exception messageText equals: failureExplanation;
148-
assertCollection: exception failures hasSameElements: {failureExplanation} ]
169+
assertCollection: exception failures hasSameElements: { failureExplanation }
170+
]
149171
]
150172

151173
{ #category : #tests }
@@ -154,19 +176,21 @@ AssertionCheckerBuilderTest >> testSeveralConditionsButOnlyOneFailed [
154176
| mathFailureExplanation |
155177

156178
mathFailureExplanation := 'An obvious math error'.
157-
checkerBuilder
158-
checking: [ :asserter |
159-
asserter
160-
enforce: [ 4 > 3 ] because: [ self fail ];
161-
enforce: [ 1 > 2 ] because: mathFailureExplanation;
162-
refuse: [ #() notEmpty ] because: [ self fail ] ].
163179
self
164-
should: [ checkerBuilder buildAndCheck ]
180+
should: [
181+
AssertionChecker check: [ :asserter |
182+
asserter
183+
enforce: [ 4 > 3 ] because: [ self fail ];
184+
enforce: [ 1 > 2 ] because: mathFailureExplanation;
185+
refuse: [ #( ) notEmpty ] because: [ self fail ]
186+
]
187+
]
165188
raise: AssertionFailed
166-
withExceptionDo: [ :exception |
189+
withExceptionDo: [ :exception |
167190
self
168191
assert: exception messageText equals: mathFailureExplanation;
169-
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
192+
assertCollection: exception failures hasSameElements: { mathFailureExplanation }
193+
]
170194
]
171195

172196
{ #category : #tests }
@@ -175,20 +199,24 @@ AssertionCheckerBuilderTest >> testSeveralConditionsButOnlyOneFailedConfiguringE
175199
| mathFailureExplanation |
176200

177201
mathFailureExplanation := 'An obvious math error'.
178-
checkerBuilder
179-
raising: InstanceCreationFailed;
180-
checking: [ :asserter |
181-
asserter
182-
enforce: [ 4 > 3 ] because: [ self fail ];
183-
enforce: [ 1 > 2 ] because: mathFailureExplanation;
184-
enforce: [ #() isEmpty ] because: [ self fail ] ].
202+
185203
self
186-
should: [ checkerBuilder buildAndCheck ]
204+
should: [
205+
AssertionChecker
206+
check: [ :asserter |
207+
asserter
208+
enforce: [ 4 > 3 ] because: [ self fail ];
209+
enforce: [ 1 > 2 ] because: mathFailureExplanation;
210+
enforce: [ #( ) isEmpty ] because: [ self fail ]
211+
]
212+
configuredBy: [ :checker | checker raising: InstanceCreationFailed ]
213+
]
187214
raise: InstanceCreationFailed
188-
withExceptionDo: [ :exception |
215+
withExceptionDo: [ :exception |
189216
self
190217
assert: exception messageText equals: mathFailureExplanation;
191-
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
218+
assertCollection: exception failures hasSameElements: { mathFailureExplanation }
219+
]
192220
]
193221

194222
{ #category : #tests }
@@ -198,21 +226,23 @@ AssertionCheckerBuilderTest >> testSeveralConditionsFailed [
198226

199227
mathFailureExplanation := 'An obvious math error'.
200228
collectionSizeFailureExplanation := 'An empty collection was not expected'.
201-
checkerBuilder
202-
checking: [ :asserter |
203-
asserter
204-
enforce: [ 1 > 2 ] because: mathFailureExplanation;
205-
enforce: [ #() notEmpty ] because: collectionSizeFailureExplanation ].
206229
self
207-
should: [ checkerBuilder buildAndCheck ]
230+
should: [
231+
AssertionChecker check: [ :asserter |
232+
asserter
233+
enforce: [ 1 > 2 ] because: mathFailureExplanation;
234+
enforce: [ #( ) notEmpty ] because: collectionSizeFailureExplanation
235+
]
236+
]
208237
raise: AssertionFailed
209-
withExceptionDo: [ :exception |
238+
withExceptionDo: [ :exception |
210239
self
211-
assert: exception messageText equals: ('<1s>. <2s>' expandMacrosWith: mathFailureExplanation with: collectionSizeFailureExplanation);
240+
assert: exception messageText
241+
equals:
242+
( '<1s>. <2s>' expandMacrosWith: mathFailureExplanation with: collectionSizeFailureExplanation );
212243
assertCollection: exception failures
213-
hasSameElements:
214-
{mathFailureExplanation.
215-
collectionSizeFailureExplanation} ]
244+
hasSameElements: { mathFailureExplanation. collectionSizeFailureExplanation }
245+
]
216246
]
217247

218248
{ #category : #tests }
@@ -221,30 +251,33 @@ AssertionCheckerBuilderTest >> testSingleConditionFailure [
221251
| explanation |
222252

223253
explanation := 'An obvious math error'.
224-
checkerBuilder checking: [ :asserter | asserter enforce: [ 1 > 2 ] because: explanation ].
225254
self
226-
should: [ checkerBuilder buildAndCheck ]
255+
should: [
256+
AssertionChecker check: [ :asserter | asserter enforce: [ 1 > 2 ] because: explanation ] ]
227257
raise: AssertionFailed
228-
withExceptionDo: [ :exception |
258+
withExceptionDo: [ :exception |
229259
self
230260
assert: exception messageText equals: explanation;
231-
assertCollection: exception failures hasSameElements: {explanation} ]
261+
assertCollection: exception failures hasSameElements: { explanation }
262+
]
232263
]
233264

234265
{ #category : #tests }
235266
AssertionCheckerBuilderTest >> testWithoutChecks [
236267

237-
self shouldnt: [ checkerBuilder buildAndCheck ] raise: AssertionFailed
268+
self shouldnt: [ AssertionChecker check: [ :asserter | ] ] raise: AssertionFailed
238269
]
239270

240271
{ #category : #tests }
241272
AssertionCheckerBuilderTest >> testWithoutFailures [
242273

243-
checkerBuilder
244-
checking: [ :asserter |
245-
asserter
246-
enforce: [ true ] because: [ self fail ];
247-
enforce: [ 1 positive ] because: [ self fail ] ].
248-
249-
self shouldnt: [ checkerBuilder buildAndCheck ] raise: AssertionFailed
274+
self
275+
shouldnt: [
276+
AssertionChecker check: [ :asserter |
277+
asserter
278+
enforce: [ true ] because: [ self fail ];
279+
enforce: [ 1 positive ] because: [ self fail ]
280+
]
281+
]
282+
raise: AssertionFailed
250283
]

0 commit comments

Comments
 (0)