Usually you have two scenarios on how you want get there.

The first is, you are creating a new rails application and you want use RSpec from the beginning.

The second is, that you already have rails application using rails tests and now you want use RSpec instead.

It is easy in both scenarios to go with RSpec. Let me describe it shortly.


Scenario 1: You are creating a new Rails Application

First lets create the project without rails test in command line:

Now Install RSpec.

Scenario 2: You already have a Rails Application

First, we have to remove the Test::Unit from our application. Go to config/application.rb and comment out the following line:

Now Install RSpec.

Install RSpec

Add rspec-rails to both the :development and :test groups in the Gemfile:

Download and install by running:

Initialize the spec/ directory (where specs will reside) with:

In Rails 4, you may want to create a binstub for the rspec command so it can be run via bin/rspec:

Once installed, RSpec will generate spec files instead of Test::Unit test files when commands likerails generate model and rails generate controller are used.

You may also invoke RSpec generators independently. For instance, running rails generate rspec:model will generate a model spec. For more information, see list of all generators.

Use RSpec Generators instead of Rails Test Generators in a Rails Application
Tagged on:     

Leave a Reply


Get every new post on this blog delivered to your Inbox.

Join other followers:

Welcome Damir Kusar

Log in

Lost your password?
%d bloggers like this: