在Rakefile中设置rspec2任务

cod*_*aig 8 ruby rake rubygems rspec2

我有一个看起来像这样的Rakefile:

require 'rspec/core/rake_task'

desc "Run all RSpec tests"
RSpec::Core::RakeTask.new(:spec)
Run Code Online (Sandbox Code Playgroud)

这不行.例如,如果我尝试运行"rake -T",我得到:

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'
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?

万一这可能对Gemfile有帮助:

source :rubygems

gemspec
Run Code Online (Sandbox Code Playgroud)

哦和一些版本:

  • Ruby:1.9.2p180
  • 耙子:0.8.7
  • Bundler:1.0.13
  • RubyGems:1.7.2

Car*_*ter 8

语法对我来说很好.您是否100%确定已rspec 2安装?它出现了gem which rspec吗?也许你忘了运行bundle install或者你没有rspec.gemspec文件中列出(开发)依赖项?


ala*_*jds 6

你在用Heroku吗?

我遇到了同样的问题,在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.
Run Code Online (Sandbox Code Playgroud)