Switch to RSpec
Published: Oct 20th, 2020
This is part of Joyful Rails, a list of recommendations to make developing your Rails app more productive and joyful.
In this article, we are talking about switching to RSpec.
When
I recommend making the switch before writing any specifications.
Why
RSpec makes it easier and more pleasant to write executable specifications for Ruby.
How
- Install Rspec. Add
rspec-rails
to theGemfile
in the test group and runbundle
. - Generate Rspec boilerplate. Run
rails generate rspec:install
. - Configure generators to generate rspec tests. Add
config.generators.test_framework = :rspec
toconfig/application.rb
. - Remove fixtures. In
spec/rails_helper.rb
remove the line starting withconfig.fixture_path =
. - 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.