8

I have a Rakefile that looks like this:

require 'rspec/core/rake_task'

desc "Run all RSpec tests"
RSpec::Core::RakeTask.new(:spec)

This isn't working though. For example, if I try to run "rake -T", I get:

code/projects/bellybuster[master]% rake -T --trace
(in /Users/craig/code/projects/bellybuster)
rake aborted!
no such file to load -- rspec/core/rake_task
/Users/craig/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/craig/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/craig/code/projects/bellybuster/Rakefile:1:in `<top (required)>'
/Users/craig/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2383:in `load'

Any thoughts?

In case it might be helpful here's the Gemfile:

source :rubygems

gemspec

Oh and some versions:

  • Ruby: 1.9.2p180
  • Rake: 0.8.7
  • Bundler: 1.0.13
  • RubyGems: 1.7.2
Nakilon
  • 34,866
  • 14
  • 107
  • 142
codecraig
  • 3,118
  • 9
  • 48
  • 62
  • 5
    I have exactly the same problem. Here are my thoughts (rants): Ruby's Package Management system is horribly broken. I'm wasting time on this stupid problem when I should be writing code. How in the world could this be?? Bundler and Gems are at the core of the Ruby ecosystem. They should be stable, simple and bulletproof. Instead it feels like a giant hacker experiment. Very sad. –  May 23 '11 at 18:22

4 Answers4

8

The syntax looks fine to me. Are you 100% sure you have rspec 2 installed? Does it appear with gem which rspec? Maybe you forgot to run bundle install or you don't list rspec in the .gemspec file as a (development) dependency?

Carl Suster
  • 5,826
  • 2
  • 22
  • 36
  • Here's the relevant parts from the gemspec: s.add_development_dependency "rake" s.add_development_dependency "rspec" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_paths = ["lib"] and gem list gives: *** LOCAL GEMS *** configuration (1.2.0) diff-lcs (1.1.2) github (0.6.2) highline (1.5.2) json_pure (1.5.1) launchy (0.3.7) minitest (1.6.0) rake (0.8.7) rdoc (2.5.8) rspec (2.6.0) rspec-core (2.6.1) rspec-expectations (2.6.0) rspec-mocks (2.6.0) text-format (1.0.0) text-hyphen (1.0.0) – codecraig May 21 '11 at 12:31
  • Hmm, well all I can think is that a) rvm is using a different gemset in the project you're working on and so it doesn't really have rspec, or b) you're missing something to do with bundler. Make sure you've got the `require 'bundler/setup'; Bundler.setup(:default, :development)` bit at the top of your Rakefile and run `bundle install` in the project directory. If this doesn't work, then reinstall rspec, or better yet, start off a [fresh gemset for your project](http://beginrescueend.com/gemsets/creating/) and let bundler handle all the installing of gems. – Carl Suster May 22 '11 at 10:21
  • Also, force RSpec 2 with `s.add_development_dependency "rspec", "~>2.0"` in the `.gemspec` since RSpec 1 used a different path for its Rake task. If there's still no development, then post more of your Rakefile above because there really aren't that many places the problem could be coming from... – Carl Suster May 22 '11 at 10:29
  • @carl-suster: so here's where I'm at. Actually, I'm going to post my latest info as an "answer" b/c it's easier to format. – codecraig May 22 '11 at 22:21
  • If you use `bundle install --system` then it should install to the default system location for gems rather than a local directory. Does RSpec work from the command line (i.e. not through rake)? It looks like probably `bundle rspec` would work for you but `rspec` wouldn't since the gem isn't installing in a system-wide place. See also the solution on [this page](http://stackoverflow.com/questions/5886307/how-to-handle-deprecated-gem-warning-sourceindexall-gems). Maybe `gem update --system` will resolve the issue if it's a bug otherwise. – Carl Suster May 23 '11 at 12:03
  • carl - I did both bundle install and gem update. I also modified my Rakefile a little bit. `require 'bundler' 5 require 'rubygems/package_task' 6 Bundler::GemHelper.install_tasks 7 8 spec = Gem::Specification.load(Dir["*.gemspec"].first) 9 Gem::PackageTask.new(spec) do |p| 10 p.need_zip = true 11 p.need_tar = true 12 end 13 14 require 'rspec/core/rake_task' 15 16 desc "Run all RSpec tests" 17 RSpec::Core::RakeTask.new(:spec) ` – codecraig May 23 '11 at 23:21
  • that looks like crap, but hopefully someone can parse that out if they need to. thanks for the help carl. – codecraig May 23 '11 at 23:21
  • Ok well I made a new directory and gemset, started a gem scaffold with `bundle gem testing` then copied in as much of the stuff you've posted as I could, then ran `bundle install`. Now `rake -T` and `rake spec` work as expected, so I can't reproduce your problem. That implies to me that something is wrong with your setup, so I really recommend making a new gemset with rvm, deleting anything installed by bundle in your project (`.bundle`, `Gemfile.lock`) and the `bundle install`ing again. There's nothing wrong with your code, just a residual problem somewhere on your system. – Carl Suster May 24 '11 at 08:05
6

Are you using Heroku?

I got the same problem, found this solution at The Fancy Manual:

## One common example using the RSpec tasks in your Rakefile. 
## If you see this in your Heroku deploy:

$ heroku run rake -T
Running `bundle exec rake -T` attached to terminal... up, ps.3
rake aborted!
no such file to load -- rspec/core/rake_task

## Now you can fix it by making these Rake tasks conditional 
## on the gem load. For example:

## Rakefile

begin
  require "rspec/core/rake_task"

  desc "Run all examples"
  RSpec::Core::RakeTask.new(:spec) do |t|
    t.rspec_opts = %w[--color]
    t.pattern = 'spec/*_spec.rb'
  end
rescue LoadError
end

## Confirm it works locally, then push to Heroku.
alanjds
  • 3,972
  • 2
  • 35
  • 43
1

Are you using Travis-CI? I fixed it by moving 'rake' from the gemspec to the Gemfile, i.e.:

source "https://rubygems.org"

# Specify your gem's dependencies in pipboy.gemspec
gemspec

group :test do
  gem 'rake'
end

Not sure if it is the correct solution, but it worked for me..

frbl
  • 1,172
  • 11
  • 17
0

I just nuked my existing gem folder and re-installed everything by running bundle install. That solved the problem for me.

markgx
  • 16
  • 2
  • 1