Setting Up RSpec in Rails Application

Installing RSpec When generating a new Rails project, just add the flag --skip-test-unit to supress creation of the test directory associated with the default Test::Unit framework as won’t be needing that. In the Gemfile, add:

group :development, :test do
  gem 'rspec-rails'
RSpec-Rails has a dependency to RSpec, so we don’t need to include it separately. Yeah, we need it in development env too. Let’s see why :
  • The development mode RSpec files add RSpec-specific generators
  • Test mode includes files to run the tests
Once you have run bundle install, Run this snippet to configure Rails to use RSpec in place of Test::Unit rails generate rspec:install This single command would generate you 4 new files :
We’ll cover more in detail regarding those later.

Updating the test database

Check for pending migrations and load the test schema rake db:test:prepare N.B Preparing your test database

Run your test suit

rspec Yup, Its simple as that… :)]]>