【问题标题】:Rake spec not running with upgraded ruby升级后的 ruby​​ 未运行 Rake 规范
【发布时间】:2013-07-13 20:39:53
【问题描述】:

我对 ruby​​ 还很陌生,我工作的公司要求我们在签入之前对代码进行本地规范测试。直到几天前,我的规范测试运行良好,但我最近升级了从默认的 OS X ruby​​ 版本 (1.8.7) 到 2.0.0,'rake spec' 现在失败并显示以下输出,我已经缩写为相关信息:

/Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-puppet-0.1.5/lib/rspec-puppet.rb:1:in `require': cannot load such file -- puppet (LoadError)
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-puppet-0.1.5/lib/rspec-puppet.rb:1:in `<top (required)>'
from /Users/Jordan/edmunds_dev/spec/spec_helper.rb:1:in `require'
from /Users/Jordan/edmunds_dev/spec/spec_helper.rb:1:in `<top (required)>'
from /Users/Jordan/edmunds_dev/modules/apache/spec/classes/apache_spec.rb:1:in `require'
from /Users/Jordan/edmunds_dev/modules/apache/spec/classes/apache_spec.rb:1:in `<top (required)>'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core- 2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-  2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/Jordan/.rvm/gems/ruby-2.0.0-p247/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
rake aborted!
/Users/Jordan/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -S rspec 

我尝试了什么:

重新安装 ruby​​ 和所有相关的 gems

更新 ruby​​gems,然后重新安装相关 gems

查看 Rakefile

我要做什么:

重新安装我的操作系统,或者直接删除名称中包含 ruby​​ 的所有内容并重新安装。

【问题讨论】:

  • 你使用 Bundler 吗?还是其他一些 gem 管理器?
  • 是的,我目前正在使用捆绑器。
  • 好的,很高兴知道。查看我的回答线程以获取更多详细信息:bundler。

标签: ruby unit-testing rake specifications


【解决方案1】:

似乎还没有为 ruby​​ 2.0.x 安装 puppet。您可能已经为 1.8.7 安装了它。所有 gem 都需要安装最新的 ruby​​ 版本。

如果使用 Bundler,请确保 puppet 在您的 Gemfile 中:

source 'https://rubygems.org'

gem 'puppet'

# Once the issue is ironed out, place this and other spec-related
# gems in the test group
gem 'rspec-puppet'

然后,确保 bundler 通过 bundle exec rake spec 加载环境。

或者手动安装,使用:

gem install puppet

查看the rspec-puppet documentation了解更多详情。

【讨论】:

  • 对不起,应该提到我试过这样做,不幸的是在运行gem install puppet之后它出现了/Users/Jordan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/ site_ruby/2.0.0/rubygems/dependency.rb:296:in to_specs': Could not find 'puppet' (&gt;= 0) among 35 total gem(s) (Gem::LoadError) from /Users/Jordan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/dependency.rb:307:in to_spec' 来自 /Users/Jordan/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems /core_ext/kernel_gem.rb:47:in gem' from /Users/Jordan/.rvm/rubies/ruby-2.0.0-p247/bin/puppet:22:in
    '
  • 好的,运行bundle list 来查看 gems bundler 正在加载什么。假设有puppet,运行bundle exec rake spec。如果puppet 不存在,请将其添加到 Gemfile 并运行 bundle
  • 好的,我通过删除 Gemfile.lock 然后再次运行 bundle install 修复了大部分问题。
  • 是的,这是清理 Gemfile.lock 的一种方法 =) 将来,您还可以运行 bundle update,它将解决所有依赖关系,然后将所有 gem 更新到最新版本满足这些依赖。我怀疑没有锁文件的bundle install 做了类似的事情。
  • 之后,我删除了系统上所有与 ruby​​ 相关的内容,以及 bash_profile 中的一行(rvm 喜欢插入其中),然后将 puppet 作为 gem 重新安装。现在可以完美运行。谢谢!
猜你喜欢
  • 2020-06-29
  • 1970-01-01
  • 2019-04-07
  • 2014-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多