Installing RSpec

Before we start testing, we’ll need to load RSpec, our testing library.

We’ll be talking about RSpec 3, which has some significant syntactical differences from previous versions. We’ll largely ignore those differences and focus on only the new syntax.

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

​ 
group :development, :test ​do​
​ 
gem ​'rspec-rails'​, ​'~> 3.1'​
​ 
​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 ...

Get Rails 4 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.