- Read Tutorial
- Watch Guide Video
In this lesson, we're going to learn the basics of RSpec, a popular testing framework for Ruby and Rails applications. Since many students have reached out to me about the principles of TDD/BDD (Test driven and Behavior drive development), I felt it should be added to the curriculum.
To start, go to the
Gemfile and in the development group, add the
gem 'rspec-rails', '`>3.0'
3.0 is to the version that would be used for this application at the time of filming.
bundle install in the command line, and this will install the
rspec gem for us. Next, run this command:
rails generate rspec:install
and this will create different *rspec files.
Now, we'll see what those rspec files look like. Go to
spec directory in your root, and inside that, you'll find two files, namely,
spec_helper.rb. Go through the content in both these files to get an idea of the different helper methods available. There's plenty of information in the form of comments to help you understand the functionality of these methods.
If you run want to run rspec, you can do it with this command:
bundle exec rspec
In the next lesson, we'll see how to create test cases.