Test Driving Rails
Test drive your Rails applications with this Minitest and fixtures guide.
- Learn about Minitest test cases, assertions, mocks and stubs.
- Design simple to use test data with fixtures.
- Write fast Rails models, controllers and system tests.
Testimonials
"Test Driving Rails is a concise yet incredibly complete guide to the patterns and tools we use to effectively test our Ruby on Rails applications, ensuring that our software does exactly what we said it would, every time we make a change."
the author of minitest/mock and RSpec
"An excellent resource for anyone aiming to master the default Rails testing framework – Minitest and fixtures."
a full-stack Rails developer
"I started a new project with factories, but thanks to this book I made my tests 32% faster with fixtures."
a Rails developer
Chapters
the author of minitest/mock and RSpec
Getting started.
Introduction to Minitest
Mocks, Stubs, Mocha, constants.
The Rails test layout.
Building test data with fixtures.
Testing models and business logic.
Testing controllers and flows.
Testing with browsers.
Continuous integration.
A handy reference.
What did we learn.
Model tests
Controller tests
System tests
Check out the preview
FAQ
Which versions of Rails are covered?
The 1st edition of the book targets Rails 8, but also works well for previous versions.
Who is the book for?
The book is designed for Rails beginners and professionals alike, but basic knowledge of Rails is assumed. Previous experience with Minitest or fixtures is not required.
Is Minitest worth it if I use RSpec?
Minitest is seemlesly integrated with Rails from the get-go. You don't need to update your gemfile or think about specific features when they come out.
What about factories?
This book talks exclusively about building test data with Rails fixtures. They are fast and reusable datasets for different tasks across development, test, and production.