Installing RSpec for Rails 3

Wed Apr 14 20:48:06 -0700 2010

Installing RSpec for Rails 3 was quite simple, here is a short guide to make sure you can also do it :)

For a Rails 3 app, simply edit the Gemfile and put this into the test section:

group :test do
  gem "rspec-rails",      ">= 2.0.0.beta"
  gem "autotest"
  gem "autotest-rails"
end

Then from your Rails root do:

$ bundle install

Once installed, you will need to tell RSpec to install itself:

 $ script/rails g rspec:install
       exist  lib
      create  lib/tasks/rspec.rake
       exist  config/initializers
      create  config/initializers/rspec_generator.rb
       exist  spec
      create  spec/spec_helper.rb
      create  autotest
      create  autotest/discover.rb

Then you should just be able to run Autotest:

 $ autotest
loading autotest/rails_rspec2
style: RailsRspec2
/Users/mikel/.rvm/rubies/ruby-1.8.7-p249/bin/ruby <snip>
........

Finished in 0.30205 seconds
8 examples, 0 failures

Nice.

blogLater

Mikel

  1. shingara Says:

    Rspec 2.0 is full compatible to Rails 3 ? or not now ?

  2. Sohan Says:

    Your post has been linked at the Drink Rails blog roll for the day.

  3. Jose Says:

    Thanks for the info.

    On a related note. It seems the RSpec bundle for TextMate needs updating. The bundle’s spec file generator (shift+control+down_arrow) is inserting the spec stub code into the source file instead of the generated spec file.

  4. daniel Says:

    Got this after following the steps:

    $ autotest
    loading autotest/rails_rspec2
    Error loading Autotest style autotest/rails_rspec2 (no such file to load — autotest/rails_rspec2). Aborting.

    help appriciated.

Leave a Reply