Installing RSpec

First, to use RSpec 3, you need a recent version of Ruby. We’ve tested our examples in this book with Ruby 2.4, and encourage you to use that version for the easiest path. You may get slightly different results on other versions of Ruby. If you’re using something older, go to the Ruby download page and grab a newer one.[9]

RSpec is made of three independent Ruby gems:

  • rspec-core is the overall test harness that runs your specs.

  • rspec-expectations provides a readable, powerful syntax for checking properties of your code.

  • rspec-mocks makes it easy to isolate the code you’re testing from the rest of the system.

You can install these individually and mix them with other test frameworks, assertion libraries, and mocking tools. But they go great together, and so we’ll be using them together in this book.

To install all of RSpec, just install the rspec gem:

 $ ​​gem install rspec -v 3.6.0
 Successfully installed rspec-support-3.6.0
 Successfully installed rspec-core-3.6.0
 Successfully installed diff-lcs-1.3
 Successfully installed rspec-expectations-3.6.0
 Successfully installed rspec-mocks-3.6.0
 Successfully installed rspec-3.6.0
 6 gems installed

You can see the three gems listed here, plus a couple of supporting libraries and the rspec wrapper gem, for a total of six gems.

Now that RSpec is on your system, let’s do a quick check to make sure it’s ready:

 $ ​​rspec --version
 RSpec 3.6
  - rspec-core 3.6.0
  - rspec-expectations 3.6.0
  - rspec-mocks 3.6.0
  - rspec-support 3.6.0

Perfect. Time to take it for a test drive.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset