17 May 2010, 10:22am
/dev/random
by

leave a comment

Rspec with Rails3 beta and Rspec 2 beta

The problem: running

spec filename.rb

against a project built on Rails 3 beta and using Rspec 2 beta generated the following error (I can’t imagine why there were any issues):

/Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `require’: no such file to load — spec/adapters/mock_frameworks/rspec (LoadError)
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `require’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:197:in `load_dependency’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `require’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/runner/options.rb:312:in `plugin_mock_framework’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/runner/options.rb:138:in `run_examples’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/runner.rb:61:in `run’
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/gems/rspec-1.3.0/lib/spec/runner.rb:45
from /Users/chris/.rvm/gems/ruby-1.8.7-p249/bin/spec:19

As you can see from the error it is in fact not running the rspec beta but rather trying to use the system’s rspec 1.3.0. Problematic, that.

Turns out the solution was to use bundle* to run the individual spec (this, of course, assumes you’re managing your gems with Bundler):

bundle exec rspec filename.rb

*In the project above I have a whole separate environment managed by RVM specifically for the latest über-stable Ruby (ruby 1.8.7 (2010-01-10 patchlevel 249) as of this writing), the Rails and Rspec beta.