An assertion checks a condition without itself becoming ordinary matched content. In regular expressions, it constrains where or when matching may continue; in testing, its truth determines whether a test passes. section 11.5.3 section 15.5.1
Regular-expression assertions include anchors for line and string positions, word-boundary checks, and lookaround conditions. The surrounding pattern must satisfy the assertion, but the assertion consumes no characters. section 11.5.3
Common regular-expression assertion forms include:
- Use \b and \B to require or reject a transition between word and non-word characters. section 11.5.3
Filtering Ruby comment lines
The regexp /^\s*#/ asserts that matching begins at the start of a line, permits leading whitespace, and then requires a hash mark. It matches " # Pure comment!" but not " x = 1 # Code plus comment!".
Assertions in MiniTest
A test assertion expresses an expected result: assert_equal(51, @deck.size) verifies that dealing one card leaves 51 cards, while a second test verifies that dealing five leaves 47. MiniTest reports the number of assertions and failures. section 15.5.1
