Ruby tests with Minitest and RSpec, from first principles
9 steps · about 4 h 40 min · Beginner
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.