← index

BuiltinAssertions

inherits Mixin · defined at test.qn:12

The 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.

Class methods

assertMeetsRequirements:Class

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.

test.qn:17

Instance methods

does:Block match:

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'

test.qn:151

does:Block notMatch:

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'

test.qn:163

does:Block resultIn:Block

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 }

test.qn:176

does:Block throw:

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/

test.qn:192

is:Block a:

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

test.qn:75

is:Block an:

Alias of is:a: that reads better before a vowel: .is:{ 6 * 7 } an:Integer.

test.qn:81

is:Block closeTo:

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.

test.qn:103

is:Block closeTo: within:

Assert |actual - expected| < toleranceis:closeTo: with the tolerance stated explicitly instead of the 1e-9 default.

.is:{ 22.0 / 7.0 } closeTo:3.14 within:0.01

test.qn:110

is:Block equalTo:

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 )

test.qn:89

is:Block greaterThan:

Assert the block's value is > expected. A failure reports actual not > expected.

test.qn:125

is:Block greaterThanOrEqualTo:

Assert the block's value is >= expected. A failure reports actual not >= expected.

test.qn:137

is:Block lessThan:

Assert the block's value is < expected. A failure reports actual not < expected.

test.qn:119

is:Block lessThanOrEqualTo:

Assert the block's value is <= expected. A failure reports actual not <= expected.

test.qn:131

is:Block notEqualTo:

Assert the block's value differs from expected under ==. A failure reports that the two compared equal.

test.qn:95

isFalse:Block

Assert the block answers exactly false. A failure reports false != {code}.

test.qn:64

isTrue:Block

Assert the block answers exactly true (not merely truthy). A failure reports true != {code}.

.isTrue:{ #(1 2 3).any?:{ |n| n == 2 } }

test.qn:59

recordResult:Block evidence:List block:Block

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.

test.qn:29