Ruby tests with Minitest and RSpec, from first principles

9 steps · about 4 h 40 min · Beginner

  1. Minitest (tutorial, Ruby Monstas, Testing for Beginners, 20 min)

    It starts from a hand-built mini test library and then shows Minitest, so you see what a test framework actually does.

  2. An introduction to Minitest: the guide I wish I had (tutorial, Rémi Mercier, 25 min)

    It shows setup and assert_equal with a realistic User class, in plain Ruby and then in Rails.

  3. Getting Started with Minitest (tutorial, Semaphore, 35 min)

    It builds a small project test-first with Bundler and introduces Minitest::Spec's describe/it style, which prepares you for RSpec.

  4. Introduction to RSpec (tutorial, The Odin Project, 35 min)

    It is a free, well-regarded intro that covers rspec --init, describe blocks, matchers and the red-green cycle.

  5. RSpec Tutorial: Test-Drive Your Ruby Code (tutorial, Semaphore, 40 min)

    You practise RSpec with TDD on a string calculator, which cements describe, it and expect.

  6. RSpec Tutorial: Ruby Testing with describe, context, expect (guide, HelpMeTest, 20 min)

    It adds context blocks, running a single spec by line number and the documentation formatter.

  7. Test Doubles (doc, RSpec official docs, 20 min)

    Now that the basics are solid, learn how to isolate code with doubles from the official executable specs.

  8. RSpec Mocks (doc, RSpec official docs, 25 min)

    It covers stubs, message expectations and verifying doubles such as instance_double, so your fakes stay honest.

  9. ruby learning (repo, GitHub, media-programming-rails, 1 h)

    For practice, you write a Minitest case for each Ruby idiom you learn, which turns testing into a habit.