public
Description: Behaviour Driven Development framework for Ruby
Home | Edit | New

config.gem (for Rails)

Issues related to configuring rspec gems in rails 2.2 (see “Check the configuration” section below for NOTES:) and 2.3 have been substantially resolved in the rspec-rails1.2.0 release.

Here are the steps to upgrade to the 1.2.0 gems on a Mac.

Install the 1.2 gems

[sudo] gem install rspec
[sudo] gem install rspec-rails

Remove the old rspec libs from the app

If you’ve got rspec, rspec-rails, dchelimsky-rspec, or dchelimsky-rspec-rails installed in vendor/gems or vendor/plugins, get rid of them (or set them aside in case you need to roll back this process).

Remove the old rspec.rake file

rm lib/tasks/rspec.rake

The old rspec.rake file is the source of most of the problems that people have experienced with configuring rspec gems in the past. It depended on rspec, so we had a catch 22 that manifested itself in numerous ways. For example, if the project didn’t bundle the gems, and you cloned the project to a new environment with no rspec installed, none of the rake tasks would work because rake would load up rspec.rake and errors would follow. That’s just one of many. Trust me – get rid of it.

Configure the gems

# in config/environments/test.rb
config.gem "rspec", :lib => false, :version => ">= 1.2.0"
config.gem "rspec-rails", :lib => false, :version => ">= 1.2.0"

NOTES:

  • use :lib => false, as we don’t need rails to ever load the libs for you (it’s managed by the rake tasks)

Check the configuration

$ rake gems RAILS_ENV=test
 - [I] rspec = 1.2.0
 - [I] rspec-rails = 1.2.0

NOTES:

  • Some people have reported to receive an error relating to dependencies (something that looks like this) when using rails 2.2. If you have the option, use rails >= 2.3, which should resolve the problem. If you do not have the option to use rails >= 2.3, then one solution is patching your lib/rails/gem_dependency.rb dependencies function with something like return [] if nil.

Bundle the gems

This part is entirely optional. If you want to bundle the gems in the app (in vendor/gems) as well, do this:

$ sudo rake gems:unpack RAILS_ENV=test
$ sudo rake gems:unpack:dependencies RAILS_ENV=test

IMPORTANT: Regenerate the rspec files

$ script/generate rspec

You MUST allow this to update the following generated files:

  • lib/tasks/rspec.rake
  • script/spec
  • script/spec_server

You need not allow this to update spec/spec_helper.rb if you have any customizations, but if you do, change the line that reads:

require 'spec'

to

require 'spec/autorun'
Last edited by hekaldama, Thu Apr 30 13:50:39 -0700 2009
Home | Edit | New
Versions: