在Rakefile中设置rspec2任务
我有一个看起来像这样的Rakefile:
require 'rspec/core/rake_task' desc "Run all RSpec tests" RSpec::Core::RakeTask.new(:spec)
这不行。 例如,如果我尝试运行“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 `' /Users/craig/.rvm/gems/ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
有什么想法吗?
万一这可能对Gemfile有帮助:
source :rubygems gemspec
哦和一些版本:
- Ruby:1.9.2p180
- 耙子:0.8.7
- Bundler:1.0.13
- RubyGems:1.7.2
语法对我来说很好。 你是100%确定你安装了rspec 2
吗? gem which rspec
出现gem which rspec
? 也许你忘了运行bundle install
或者你没有在.gemspec
文件中列出rspec
作为(开发)依赖项?
你在用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.
你在使用Travis-CI吗? 我通过将’rake’从gemspec移动到Gemfile来修复它,即:
source "https://rubygems.org" # Specify your gem's dependencies in pipboy.gemspec gemspec group :test do gem 'rake' end
不确定它是否是正确的解决方案,但它对我有用..
我刚刚修改了我现有的gem文件夹,并通过运行bundle install
重新安装了所有内容。 这解决了我的问题。