Testing for Rubys
Testing in Ruby is the practice of writing automated checks for code, mainly with Minitest, which ships with Ruby, or RSpec, a popular alternative with a descriptive syntax. Tests set up data, run a method and assert the result. Doubles and stubs replace slow or external parts so tests stay fast.
Stage: Tooling · Part of the Ruby roadmap · Last reviewed 19 November 2026
What to learn in Testing
- Write a Minitest test class with assertions
- Describe behaviour using RSpec describe, it and expect
- Use before hooks or let to set up shared data
- Replace an external call with a stub or double
- Run a single test file and read failure output
Testing interview questions
What is the difference between Minitest and RSpec?
Minitest is included with Ruby and uses plain classes and assertion methods, or a light spec style. RSpec is a separate gem with a richer, more readable DSL, built-in matchers and mocks. Both do the same job, and the choice is mostly team preference.
When is it appropriate to stub a method in a test?
Stub things outside the unit under test that are slow, random or hard to trigger, such as network calls, the clock or payment gateways. Avoid stubbing the object you are testing, since that proves nothing about its real behaviour.
Where Testing fits in the Ruby roadmap
Testing belongs to the Tooling stage (beginner level), which takes about 12 hours. The ecosystem.