Installing RSpec

Before you start testing, you’ll need to load RSpec, your testing library.

To add RSpec to a Rails project, add the rspec-rails gem to your Gemfile:

 group ​:development​, ​:test​ ​do
  gem ​"rspec-rails"​, ​"~> 3.7.0"
 end

The rspec-rails gem depends on the rspec gem proper. The rspec gem is mostly a list of other dependencies where the real work gets done, including rspec-core, rspec-expectations, and rspec-mocks. Sometimes rspec and rspec-rails are updated separately; you might choose to explicitly specify both versions in the Gemfile. Here we’re putting rspec in the development group as well as in the test group so that you can call rspec from the command line, where development mode is the default. (RSpec switches ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.