Skip to content

Commit 0c1847f

Browse files
authored
Merge pull request #77 from ba-st/assertion_checker_improvements
Let AssertionChecker as the entry point for using the library
2 parents b13c72c + 6c5bb38 commit 0c1847f

File tree

9 files changed

+195
-149
lines changed

9 files changed

+195
-149
lines changed

.github/workflows/loading-groups.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
load-spec: [ deployment, dependent-sunit-extensions, tests, tools, development ]
1313
name: ${{ matrix.smalltalk }} + ${{ matrix.load-spec }}
1414
steps:
15-
- uses: actions/checkout@v2
15+
- uses: actions/checkout@v3
1616
- uses: hpi-swa/setup-smalltalkCI@v1
1717
with:
1818
smalltalk-image: ${{ matrix.smalltalk }}

.github/workflows/unit-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
smalltalk: [ Pharo64-10, Pharo64-9.0, Pharo64-8.0, Pharo64-7.0, Pharo32-7.0 ]
1111
name: ${{ matrix.smalltalk }}
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
- uses: hpi-swa/setup-smalltalkCI@v1
1515
with:
1616
smalltalk-image: ${{ matrix.smalltalk }}
@@ -23,3 +23,4 @@ jobs:
2323
uses: codecov/codecov-action@v3
2424
with:
2525
name: Unit-Tests-${{matrix.smalltalk}}
26+
token: ${{ secrets.CODECOV_TOKEN }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Quick links
2929
- Additional Math abstractions
3030
- Bindings and Optionals
3131
- Exception Handling extensions
32-
- Metaprogramming
32+
- Meta-programming
3333
- SUnit extensions
3434

3535
## License

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ understanding over specific topics:
1717
required values, that can be unknown at the beginning of an execution.
1818
See the [related documentation.](reference/BindingsAndOptionals.md)
1919
- **Exception Handling**: Extensions to the [exception handling mechanics](reference/ExceptionHandling.md).
20-
- **Metaprogramming**: Some abstractions like [namespaces](reference/Namespaces.md)
20+
- **Meta-programming**: Some abstractions like [namespaces](reference/Namespaces.md)
2121
and [interfaces](reference/Interfaces.md).
2222
- **SUnit**: [Extensions to the SUnit framework](reference/SUnit.md).
2323

docs/reference/Collections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ iterator next "$b".
8484

8585
## Ordered Set
8686

87-
An `OrderderSet` is a set preserving the element's insertion order. It complies
87+
An `OrderedSet` is a set preserving the element's insertion order. It complies
8888
with the sequenceable collection protocol.
8989

9090
```smalltalk

docs/reference/Comparison.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It will apply the combinator operator to each one of the objects:
1717
collection and then combine them.
1818
- `combineHashOf:with:` will send the hash message to the two objects and then
1919
combine them.
20-
- `combineAll::` expectes a collection of hashes and will combine them.
20+
- `combineAll::` expects a collection of hashes and will combine them.
2121
- `combine:with:` will combine two hash values
2222

2323
### Hash Combinator Examples
@@ -42,7 +42,7 @@ Equality checkers always performs a `==` comparison first and proceed with the
4242
rest of the rules only if the objects are not identical.
4343

4444
By default `equalityChecker` is an instance of `PropertyBasedEqualityChecker`
45-
and it alredy knowns the receiving instance. It can be configured with:
45+
and it already knowns the receiving instance. It can be configured with:
4646

4747
- `compare: selector` will add a rule to the checker that sends the provided
4848
message on the receiver and target object and compare the results by `=`

docs/tutorial/Assertions.md

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,39 @@ a valid code consists only of letters. So let's rewrite our example:
3737
3838
code := 'AR'.
3939
40-
AssertionCheckerBuilder new
41-
checking: [ :asserter |
40+
AssertionChecker
41+
check: [ :asserter |
4242
asserter
4343
enforce: [ code size = 2 ]
4444
because: 'ISO 3166-1 Alpha-2 codes must have exactly two letters';
4545
enforce: [ code allSatisfy: #isLetter ]
4646
because: 'ISO 3166-1 Alpha-2 codes must only contain letters'
47-
];
48-
buildAndCheck
47+
]
4948
```
5049

51-
Note that in this case we are creating an `AssertionCheckerBuilder` and
52-
configuring all the conditions to enforce. Let's try now replacing `code` with
53-
`'AR3'` and `Do it` again. By default all the conditions to enforce are checked
54-
so you should get an error message combining both explanations, and if you
55-
handle the raised exception you can get all the failures by sending it the
56-
message `failures`.
50+
Note that in this case we are configuring all the conditions to enforce. Let's
51+
try now replacing `code` with `'AR3'` and `Do it` again. By default all the
52+
conditions to enforce are checked so you should get an error message combining
53+
both explanations, and if you handle the raised exception you can get all the
54+
failures by sending it the message `failures`.
5755

5856
If you want the more usual behavior of stopping after the first failure you can
59-
configure the builder to fail fast:
57+
configure it to fail fast:
6058

6159
```smalltalk
6260
| code |
6361
6462
code := 'AR3'.
6563
66-
AssertionCheckerBuilder new
67-
failFast;
68-
checking: [ :asserter |
64+
AssertionChecker
65+
check: [ :asserter |
6966
asserter
7067
enforce: [ code size = 2 ]
7168
because: 'ISO 3166-1 Alpha-2 codes must have exactly two letters';
7269
enforce: [ code allSatisfy: #isLetter ]
7370
because: 'ISO 3166-1 Alpha-2 codes must only contain letters'
74-
];
75-
buildAndCheck
71+
]
72+
configuredBy: [ :checker | checker failFast ]
7673
```
7774

7875
If you `Do it` you will get only the first failure, the next conditions won't
@@ -90,19 +87,18 @@ valid code. Now we will consider only the officially assigned codes as valid:
9087
code := 'AA'.
9188
officiallyAssignedCodes := #('AR' 'BR' 'US').
9289
93-
AssertionCheckerBuilder new
94-
checking: [ :asserter |
90+
AssertionChecker
91+
check: [ :asserter |
9592
asserter
9693
enforce: [ code size = 2 and: [ code allSatisfy: #isLetter ]]
9794
because: 'ISO 3166-1 Alpha-2 codes must have exactly two letters'
98-
onSuccess: [ :sucessAsserter |
99-
sucessAsserter
95+
onSuccess: [ :successAsserter |
96+
successAsserter
10097
enforce: [ officiallyAssignedCodes includes: code ]
10198
because: [ '<1s> is not an officially assigned code'
10299
expandMacrosWith: code ]
103100
]
104-
];
105-
buildAndCheck
101+
]
106102
```
107103

108104
Here we are introducing two new features:
@@ -112,8 +108,7 @@ Here we are introducing two new features:
112108
is satisfied. So we can make assumptions about what `code` looks like at this point.
113109
- Second, using a block as the `because:` argument. This avoids creating
114110
unnecessary objects because the explanation will only be evaluated if the
115-
condition is not met. In this case the argument is a literal String, so it
116-
makes no difference.
111+
condition is not met.
117112

118113
## Refusing
119114

@@ -126,26 +121,25 @@ Sometimes it's easier to explain a condition using negative logic, so
126121
code := 'AR'.
127122
unassignedCodes := #('LO' 'LP' 'OU').
128123
129-
AssertionCheckerBuilder new
130-
checking: [ :asserter |
124+
AssertionChecker
125+
check: [ :asserter |
131126
asserter
132127
enforce: [ code size = 2 and: [ code allSatisfy: #isLetter ]]
133128
because: 'ISO 3166-1 Alpha-2 codes must have exactly two letters'
134-
onSuccess: [ :sucessAsserter |
135-
sucessAsserter
129+
onSuccess: [ :successAsserter |
130+
successAsserter
136131
refuse: [ unassignedCodes includes: code ]
137132
because: [ '<1s> is an unassigned code' expandMacrosWith: code ]
138133
]
139-
];
140-
buildAndCheck
134+
]
141135
```
142136

143137
## Configuring the error to raise
144138

145139
If not specified the library will raise `AssertionFailed` when some check fails.
146140
If you want to raise a different kind of error there are two ways to configure it:
147141

148-
For single condition checks you can use `enforce:because:raising:` or `refuse:because:raising:`.
142+
For single condition checks, use `enforce:because:raising:` or `refuse:because:raising:`
149143

150144
```smalltalk
151145
| code |
@@ -158,24 +152,25 @@ AssertionChecker
158152
raising: Error
159153
```
160154

161-
When using the builder you should use:
155+
For multiple condition checks, use:
162156

163157
```smalltalk
164158
| code |
165159
166160
code := 'AR'.
167161
168-
AssertionCheckerBuilder new
169-
raising: InstanceCreationFailed;
170-
checking: [ :asserter |
162+
AssertionChecker
163+
check: [ :asserter |
171164
asserter
172165
enforce: [ code size = 2 ]
173166
because: 'ISO 3166-1 Alpha-2 codes must have exactly two letters';
174167
enforce: [ code allSatisfy: #isLetter ]
175168
because: 'ISO 3166-1 Alpha-2 codes must only contain letters'
176-
];
177-
buildAndCheck
169+
]
170+
configuredBy: [ :checker |
171+
checker raising: InstanceCreationFailed
172+
]
178173
```
179174

180-
but keep in mind when using the builder that the error to raise must understand
175+
but keep in mind when using multiple conditions, that the error to raise must understand
181176
`signalAll:` in order to work.

0 commit comments

Comments
 (0)