Switch to RSpec
Published: October 20, 2020
This is part of The Annotated Guide to a New Rails App, a list of recommendations to make developing your Rails app more productive and joyful.
In this article, we are talking about switching to RSpec.
I recommend making the switch before writing any specifications.
RSpec makes it easier and more pleasant to write executable specifications for Ruby.
- Install Rspec. Add
Gemfilein the test group and run
- Generate Rspec boilerplate. Run
rails generate rspec:install.
- Configure generators to generate rspec tests. Add
config.generators.test_framework = :rspecto
- Remove fixtures. In
spec/rails_helper.rbremove the line starting with
- Remove minitest boilerplate.
git rm -r test/.
- Make a commit
Test that this works by running
rails generate model foo.
You should get a migration, a model file, and an RSpec spec file for the model.
You should not get any Minitest files. RSpec (
rspec) should run successfully.
Remove the files created by the generator.