BuiltinAssertionsThe assertion vocabulary test methods write against (isTrue:, is:equalTo:, does:throw:, …) — a Mixin, mixed into Test. Every assertion takes the value under test as a BLOCK (.is:{ 1 + 1 } equalTo:2) so it can be timed and its source location reported; each one records a TestAssertionResult through the host's addResult: — a failure is evidence for the reporter, not a thrown error, so the test keeps running.
Mixin contract check, run when a class mixes BuiltinAssertions in: the host must implement addResult: (the sink every assertion files its TestAssertionResult into), or this throws.
Assert the block's value, used as the pattern, ~-matches expected: a Regex value matches the string, a Range value contains the number, a Class value matches an instance. A failure reports that it didn't match.
.does:{ (1..5) } match:3 .does:{ #/qu.+n/ } match:'quoin'
Assert the block's value, used as the pattern, does NOT ~-match expected (see does:match:). A failure reports that it matched.
.does:{ #/xyz/ } notMatch:'quoin'
Run the block for its effects, then assert expectedBlock answers exactly true — for checking state after an action rather than the action's own value.
var list = #(); .does:{ list.add:1 } resultIn:{ list.count == 1 }
Assert the block throws, and that expectedError matches what was thrown: an error Class, or a regex/string matched against both the error value and its message string. A failure reports what was thrown instead (nil when the block completed without throwing).
.does:{ 1 / 0 } throw:ArithmeticError .does:{ 1 / 0 } throw:#/Division by zero/
Assert the block's value is an instance of expected — matched with ~, so any pattern ~ accepts works. A failure reports expected !~ actual.
.is:{ 6 * 7 } a:Integer
Alias of is:a: that reads better before a vowel: .is:{ 6 * 7 } an:Integer.
Approximate float comparison: |actual - expected| < tolerance. closeTo: uses a default tolerance (1e-9), enough to absorb last-ULP variation in non-correctly-rounded libm results (log/exp/pow/trig) across platforms; closeTo:within: sets the tolerance explicitly.
Assert |actual - expected| < tolerance — is:closeTo: with the tolerance stated explicitly instead of the 1e-9 default.
.is:{ 22.0 / 7.0 } closeTo:3.14 within:0.01
Assert the block's value == expected — the workhorse assertion. A failure reports expected != actual.
.is:{ (1..5).collect:{ |n| n * 10 } } equalTo:#( 10 20 30 40 )
Assert the block's value is > expected. A failure reports actual not > expected.
Assert the block's value is >= expected. A failure reports actual not >= expected.
Assert the block's value is < expected. A failure reports actual not < expected.
Assert the block's value is <= expected. A failure reports actual not <= expected.
Assert the block's value differs from expected under ==. A failure reports that the two compared equal.
Assert the block answers exactly false. A failure reports false != {code}.
Assert the block answers exactly true (not merely truthy). A failure reports true != {code}.
.isTrue:{ #(1 2 3).any?:{ |n| n == 2 } }
The primitive every assertion funnels through: run testBlock (a pass is answering exactly true), time it, file a TestAssertionResult carrying the #( expected comparison actual ) evidence triple plus the asserted block's name and source location, and notify the reporter. Answers the recorded result — build custom assertions on this.