Ssetting up rspec2 task in Rakefile

蓝咒 提交于 2019-12-22 04:33:26

问题


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

回答1:


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?




回答2:


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.



回答3:


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..




回答4:


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



来源:https://stackoverflow.com/questions/6079495/ssetting-up-rspec2-task-in-rakefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!