3

I'm dealing with a problem that has been annoying me for quite a while. For some reason, I can't get rspec started on my local machine. I've tried various approaches to install and run it, but none of them worked. I am running Ruby on Rails 2.3.5 with Ruby 1.8.7 on a git repository using bundler.

First of all, I tried to install rspec as a gem. For that purpose, I added the following entries to my Gemfile:

group :test do
  gem 'rspec', '=1.3.0'
  gem "rspec-rails", "=1.3.2"
end
...
group :cucumber do
  gem 'rspec', '=1.3.0'
  gem "rspec-rails", "=1.3.2"  
end

When I check with

gem list

I get to see

*** LOCAL GEMS ***
(...)
rspec (1.3.0)
rspec-rails (1.3.2)

So, it must be there. Then I created a spec file in /spec/model/bookmark_step.rb. But when I try to run it with

rspec spec/model/bookmark_spec.rb

I get

The program 'rspec' is currently not installed.  You can install it by typing:
sudo apt-get install ruby-rspec-core

When using

bundle exec spec

I get

bundler: command not found: rspec Install missing gem executables with bundle install

Ok, so far so bad. Let's try something else. Why not install from the ubuntu sources (I'm working on Ubuntu 12.04):

sudo apt-get install ruby-rspec-core

Suggested packages: ruby-rspec The following NEW packages will be installed: ruby-rspec-core 0 upgraded, 1 newly installed, 0 to remove and 73 not upgraded.

Ok, let's roll by typing

rspec spec/model/bookmark_spec.rb

Guess what I'm getting ...

/var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant RSpec::Core::Formatters (NameError)
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
from /var/lib/gems/1.8/gems/rspec_spinner-2.0.0/lib/rspec_spinner/base.rb:12
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
from /var/lib/gems/1.8/gems/rspec_spinner-2.0.0/lib/rspec_spinner.rb:4
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:68:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `each'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:66:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `each'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler/runtime.rb:55:in `require'
from /var/lib/gems/1.8/gems/bundler-1.1.5/lib/bundler.rb:119:in `require'
from (...) Workspace/config/boot.rb:116:in `load_gems'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:164:in `process'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'
from /var/lib/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
from (...)  Workspace/config/environment.rb:28
from (...)  Workspace/spec/model/../spec_helper.rb:4:in `require'
from (...)  Workspace/spec/model/../spec_helper.rb:4
from (...)  Workspace/spec/model/bookmark_spec.rb:2:in `require'
from (...)  Workspace/spec/model/bookmark_spec.rb:2
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `map'
from /usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:386:in `load_spec_files'
from /usr/lib/ruby/vendor_ruby/rspec/core/command_line.rb:18:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:55:in `run_in_process'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:46:in `run'
from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:10:in `autorun'
from /usr/bin/rspec:4

Ok, that last thing might be a version mismatch. I guess ubuntu installs rspec for rails 3 while I need rspec for rails 2.3.5. But I've tried a lot to make it work. I suppose that was the wrong way, anyway, so i eventually stopped looking for the exact cause of that last error message.

Does anyone have a guess what else I could try? Or maybe something I should change?

3
  • Did you try bundle exec rspec (instead of bundle exec spec)? Oct 7, 2012 at 15:16
  • Thanks for the tip. I tried both spec and rspec. With ruby-rspec-core installed from the Ubuntu sources, it kind of runs, but doesn't really execute the given specs. When I type in bundle exec rspec, the result then looks like that: <Proc:0xb731cd80@/usr/lib/ruby/vendor_ruby/rspec/core/configuration.rb:50>} is excluding everything? Finished in 0.00003 seconds 0 examples, 0 failures
    – Andy M
    Oct 7, 2012 at 16:39
  • And using bundle exec rspec spec/model/bookmark_spec.rb gives me the error mentioned earlier ...
    – Andy M
    Oct 7, 2012 at 16:48

2 Answers 2

2

For some reason, I've noticed on Ubuntu that the environment isn't loaded early enough to trigger bundler loading the test group gems. I haven't figured out the root cause yet but running my tests like this works:

RAILS_ENV=test bundle exec rspec

0

We've been using the following for our rails 2.3.14 application. I guess it should work for 2.3.5 too...

group :development, :test do
  gem "rspec-rails", "1.3.4"
  gem "steak"
  gem "factory_girl", "2.6.4"
  gem "database_cleaner"
end

group :test do
  gem "mocha"
  gem "capybara", "~> 0.3.9"
end
1
  • Ok, thanks for the answer. I tried that one, too. The outcome is the following error: /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in load_missing_constant': uninitialized constant RSpec::Core::Formatters (NameError) from /var/lib/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in const_missing' (...). However, it's defintily installed on my system. I checked with gem list: rspec (1.3.1, 1.3.0) rspec-rails (1.3.4, 1.3.2) It seems to be less a version problem and much more an installation issue ...
    – Andy M
    Oct 26, 2012 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.