-
Notifications
You must be signed in to change notification settings - Fork 0
RSpec
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.
-
An Introduction to RSpec - gives a good breakdown of RSpec syntax.
-
RSpec Matchers - important to understand how to use matchers in order to write specs.
-
Better Specs - Best practices for writing specs