Skip to content
Thuy edited this page Jun 27, 2017 · 15 revisions

RSpec is a testing framework written in Ruby for testing Ruby code. There are other testing frameworks/libraries for Ruby, but RSpec is one of the most used and I personally find it more readable.

From the command line, check to make sure you have RSpec installed

rspec -v

If you don't get back an RSpec version number, you will need to install RSpec. Go to RSpec - Getting Started for installation instructions.


After installing RSpec, add a Gemfile to your project directory called Gemfile. In the file add this code:

source "https://rubygems.org"

gem "rspec"

Inside the directory of your project, run this code from the command line to fetch the rspec gems and resolve dependencies:

bundle install

Note that this adds a file called Gemfile.lock. You will never have to touch this code so ignore it.


Now you should be able to run tests from the command line like so:

rspec

We will learn how to write tests and start with the tests running red and work to solve it and turn it green.

References

Clone this wiki locally