liveBook · Manning

Assert_equal

As explained in The Well-Grounded Rubyist, Fourth Edition

assert_equal is a Minitest assertion method that compares an expected value with an actual value using Ruby equality.

assert_equal compares an expected value with an actual value using Ruby's == operator. Matching values pass the assertion; differing values fail it. section 15.5.1

Checking a deck after dealing

After dealing one card, assert_equal(51, @deck.size) verifies that the deck contains 51 cards. After dealing five, assert_equal(47, @deck.size) performs the corresponding check.

Minitest counts each call as an assertion and reports failures separately from errors. A custom MicroTest implementation builds assert_equal by comparing its arguments, passing the result to assert, and displaying both values when the comparison fails. section 15.5.1 section 15.5.2

How The Well-Grounded Rubyist, Fourth Edition covers it

How deep it goes
Explains argument comparison, Ruby equality, result reporting, and a small custom implementation.
Examples
Demonstrates deck-size checks after dealing one card or five cards, including passing and deliberately failing assertions.
What it assumes
Assumes Ruby method calls and equality, while demonstrating test methods, setup, and automatic test execution.
What you can do after
Apply it via Minitest to verify expected results and interpret assertion counts, failures, errors, and diagnostic values.
How it connects
Connects equality assertions with Ruby's == operator, Minitest, test methods, setup, and assertion reporting.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Rubyist, Fourth Edition. The section links point to the parts of the book it draws on.