Intro to TDD/BDD with the RSpec Testing Framework
In this lesson, we're going to learn the basics of RSpec, a popular testing library for Ruby and Rails applications. Since many students have reached out to me about this topic, I felt it should be added to the curriculum.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

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 rspec-rails gem.

gem 'rspec-rails', '`>3.0'

3.0 is to the version that would be used for this application at the time of filming.

Then run 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.

large

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, rails_helper.rb and 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

large

In the next lesson, we'll see how to create test cases.