no such file to load -- rspec/matchers - rspec-rails, shoulda, cucumber, factory girl, Rails2.3.10
Asked Answered
A

3

8

I've inherited an old Rails2.3 app. It's very complex and has (shock, horror) no tests whatsoever. I'm used to rspec and cucumber so I thought I'd start working on getting specs and features defined for the eventual (long-away) upgrade to Rails 3. It's easier to upgrade if I know exactly what will fail.

Anyway, I found it very difficult to find resources on the internet that show how to set up rspec, cucumber, factory girl, and shoulda in a rails 2.3 environment. My bundle is as follows:

source "http://rubygems.org"

# Production gems
gem "rails",    "2.3.10"
gem "nokogiri", "1.4.4"
gem "mysql",    "~> 2.8.1"

group :development do
  # bundler requires these gems in development
  gem 'rspec',          '1.3.2'
  gem 'rspec-core',     '2.5.2'
  gem 'rspec-rails',    '1.3.4'
end

group :test do
  # bundler requires these gems while running tests
  gem 'cucumber-rails', '0.4.1'
  gem 'factory_girl'
  gem 'shoulda',        '2.11.3'
  gem 'shoulda-matchers'
end

When I go to run

bundle exec rspec spec, 

I get the following stacktrace from shoulda:

/Users/sys/src/proj/rails/ruby/1.8/gems/shoulda-2.11.3/lib/shoulda/integrations/rspec2.rb:8: no such file to load -- rspec/matchers (MissingSourceFile)
    from /Users/sys/src/proj/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in `require'
    from /Users/sys/src/proj/vendor/rails/activesupport/lib/active_support/dependencies.rb:184:in `require'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/shoulda-2.11.3/lib/shoulda.rb:4
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:68:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:66:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `each'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/runtime.rb:55:in `require'
    from /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler.rb:120:in `require'
    from /Users/sys/src/proj/config/boot.rb:119:in `load_gems'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:164:in `process'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:113:in `send'
    from /Users/sys/src/proj/config/../vendor/rails/railties/lib/initializer.rb:113:in `run'
    from /Users/sys/src/proj/config/environment.rb:12
    from /Users/sys/src/proj/spec/spec_helper.rb:4:in `require'
    from /Users/sys/src/proj/spec/spec_helper.rb:4
    from /Users/sys/src/proj/spec/models/announcement_spec.rb:1:in `require'
    from /Users/sys/src/proj/spec/models/announcement_spec.rb:1
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `map'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/configuration.rb:386:in `load_spec_files'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:55:in `run_in_process'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:46:in `run'
    from /Users/sys/src/proj/rails/ruby/1.8/gems/rspec-core-2.5.2/lib/rspec/core/runner.rb:10:in `autorun'
    from /Users/sys/src/proj/rails/ruby/1.8/bin/rspec:19

Googling for that error provides frighteningly few hits... I'm not sure what I've done wrong?

Removing rspec-core gives:

bundle exec rspec spec/models/announcement_spec.rb /Users/sys/.rvm/gems/ree-1.8.7-2011.03@proj/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:143:in `gem': rspec-core is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

contents of opt/local/bin/rspec

cat /opt/local/bin/rspec 
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec-core' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
  version = $1
  ARGV.shift
end

gem 'rspec-core', version
load Gem.bin_path('rspec-core', 'rspec', version)

I wonder if this is conflicting with other rspec's I have installed (I've a Rails3 app installed, also with bundler/rvm)... Not sure why rspec is being run out of opt/local/bin and not the bundle, though..

Ascendancy answered 2/6, 2011 at 13:58 Comment(0)
M
11

I ran into this same problem. After hunting down all binary rspec commands (several locations), I belatedly realized that the 1.3.2 branch of RSPEC titles its binary "spec" and not "rspec".

So the correct commands was always "bundle exec spec spec/models/..." Putting "rspec" meant that bundler failed to find it in my current rvm/gemset and went searching through my entire path, eventually coming up with an /opt/local/bin copy that belonged to an rspec2.x install.

It is possible that an alias allows rspec 1.3.2 to also respond to the "rspec" command, but that was not the case for me. Using "spec" was 100% reliable for avoiding that call for rspec-core and other 2.x modules.

Thanks for the question and all the research above. Charles

Malpighiaceous answered 21/6, 2011 at 0:41 Comment(0)
F
1

It looks like rspec-core, which is from a version of rspec that only supports Rails 3, may be the problem. Try uninstalling that and removing it from your Gemfile.

For comparison, here's a section from our Gemfile that works fine for Rails 2.3:

group :development, :local, :test do                                             
  gem "rspec",              "= 1.3.1"                                            
  gem "rspec-rails",        "= 1.3.3"                                            
  gem "factory_girl",       "= 1.3.3"                                            
  gem "webrat",             "= 0.7.3"                                            
  gem "shoulda",            "= 2.11.3"                                           
end        
Fredella answered 2/6, 2011 at 14:9 Comment(5)
If I remove rspec-core, I get: /Library/Ruby/Gems/1.8/gems/bundler-1.0.14/lib/bundler/rubygems_integration.rb:143:in `gem': rspec-core is not part of the bundle. Add it to Gemfile. (Gem::LoadError) from /Users/sys/src/proj/rails/ruby/1.8/bin/rspec:18Ascendancy
I'd try uninstalling all rspec gems, putting just the above 2 gems in your Gemfile, and running bundle install.Fredella
Still causes problems. However, now it's complaining that the file is in from /opt/local/bin/rspec:18... what's your file contents of that script?Ascendancy
To make sure you're running the correct executables, use bundle exec, e.g. bundle exec rake spec.Fredella
You know, it would really be helpful to have a site which lists all the dependencies for a given version of rails for different gem environments. There's tons of questions like this, but very few definitive answers (a lot of answers are partial and miss various dependencies). Unfortunately, bundler can't always pick the right versions for you!Tanager
H
1

A bundle update rspec-rails fixed this issue for me on rails 3.1.

Hocker answered 23/3, 2012 at 16:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.