Test Ruby code with Minitest and doubles

8 steps · about 2 h 25 min · Beginner

  1. Minitest overview: test runner, specs and benchmarks (reference, Ruby Standard Library Docs, 15 min)

    Understand how minitest/autorun discovers test classes and integrates assertions, mocks and specs.

  2. Minitest::Test lifecycle (setup, teardown and test methods) (reference, Ruby Standard Library Docs, 20 min)

    Structure isolated test cases with setup and teardown hooks so state never leaks between tests.

  3. Minitest::Assertions reference (reference, Ruby Standard Library Docs, 25 min)

    Choose the right assertion—assert_equal, assert_raises, assert_in_delta, refute and assert_match—for readable failure messages.

  4. Ruby Exception hierarchy for testing error paths (reference, Ruby 3.3 Core Docs, 15 min)

    Know StandardError vs RuntimeError vs custom exception subclasses when writing assert_raises checks.

  5. Verifying collaborations with Minitest::Mock and stub (reference, Ruby Standard Library Docs, 20 min)

    Expect specific method calls with Minitest::Mock and stub external calls cleanly using block-scoped Object#stub.

  6. Describe/it syntax with Minitest::Spec (reference, Ruby Standard Library Docs, 15 min)

    See how Minitest's spec DSL maps describe/it blocks directly onto Minitest::Test classes.

  7. Organizing lib/ and test/ in a Ruby gem (guide, RubyGems Guides, 20 min)

    Place test files beside lib/ and run the suite consistently with rake test.

  8. Minitest repository and current release notes (repo, GitHub (minitest/minitest), 15 min)

    Check modern Minitest options, parallel test execution and plugin hooks in the upstream repository.