Ruby on Rails - 运行黄瓜时出错:您已经激活了activesupport 3.2.1,但您的Gemfile需要activesupport 3.1.0。

时间:2012-03-12 17:36:12

标签: ruby-on-rails cucumber rvm

我知道这个问题之前已经以一种形式或另一种形式提出过,但我仍然无法为此找到有效的解决方案。

我正在网上提供saas课程,代码是直接克隆的 https://github.com/saasbook/hw3_rottenpotatoes

当我从命令提示符运行黄瓜时

Using the default profile...
You have already activated activesupport 3.2.1, but your Gemfile requires activesupport 3.1.0. Using bundle exec may solve this. (Gem::LoadError)
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/runtime.rb:17:in `setup'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/setup.rb:7:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/boot.rb:6:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/application.rb:1:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/environment.rb:2:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-rails-1.3.0/lib/cucumber/rails.rb:7:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/features/support/env.rb:7:in `<top (required)>'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:40:in `run!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:20:in `execute'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/bin/cucumber:14:in `<top (required)>'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/cucumber:19:in `load'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/cucumber:19:in `<main>'

运行捆绑安装版本后,我得到一个更加丑陋的消息

Could not find rack-cache (~> 1.1) amongst [actionmailer-3.1.0, actionpack-3.1.0, activemodel-3.1.0, activerecord-3.1.0, activeresource-3.1.0, activesupport-3.1.0, addressable-2.2.7, archive-tar-minitar-0.5.2, arel-2.2.1, bcrypt-ruby-3.0.1, builder-3.0.0, capybara-1.1.2, childprocess-0.3.1, coffee-rails-3.1.1, coffee-script-2.2.0, coffee-script-source-1.2.0, columnize-0.3.6, cucumber-1.1.8, cucumber-rails-1.3.0, cucumber-rails-training-wheels-1.0.0, database_cleaner-0.7.1, diff-lcs-1.1.3, erubis-2.7.0, execjs-1.3.0, ffi-1.0.11, gherkin-2.8.0, haml-3.1.4, hike-1.2.1, i18n-0.6.0, jquery-rails-1.0.19, json-1.6.5, json_pure-1.6.5, launchy-2.0.5, libv8-3.3.10.4-x86_64-darwin-10, linecache19-0.5.12, mail-2.3.0, mime-types-1.17.2, multi_json-1.1.0, nokogiri-1.5.0, polyglot-0.3.3, rack-1.3.6, rack-cache-1.0.3, rack-mount-0.8.3, rack-ssl-1.3.2, rack-test-0.6.1, rails-3.1.0, railties-3.1.0, rake-0.9.2.2, rdoc-3.12, ruby-debug-base19-0.11.25, ruby-debug19-0.11.6, ruby_core_source-0.1.5, rubyzip-0.9.6.1, sass-3.1.15, sass-rails-3.1.5, selenium-webdriver-2.13.0, sprockets-2.0.3, sqlite3-1.3.5, term-ansicolor-1.0.7, therubyracer-0.9.10, thor-0.14.6, tilt-1.3.3, treetop-1.4.10, tzinfo-0.3.31, uglifier-1.2.3, xpath-0.1.4] (Gem::LoadError)
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:451:in `block in find_in_unresolved'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:451:in `map'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/specification.rb:451:in `find_in_unresolved'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:43:in `require'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/dsl.rb:1:in `<top (required)>'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/definition.rb:17:in `build'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler.rb:138:in `definition'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler.rb:126:in `load'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/bundler-1.0.21/lib/bundler/setup.rb:7:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require' 
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/boot.rb:6:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/application.rb:1:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/config/environment.rb:2:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-rails-1.3.0/lib/cucumber/rails.rb:7:in `<top (required)>'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/Users/chemin/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Users/chemin/rails_projects/saas/hw3_rottenpotatoes/features/support/env.rb:7:in `<top (required)>'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/rb_support/rb_language.rb:129:in `load_code_file'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:171:in `load_file'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:175:in `load_step_definitions'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/runtime.rb:40:in `run!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:43:in `execute!'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/lib/cucumber/cli/main.rb:20:in `execute'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/cucumber-1.1.9/bin/cucumber:14:in `<top (required)>'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/cucumber:19:in `load'
/Users/chemin/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/bin/cucumber:19:in `<main>'

2 个答案:

答案 0 :(得分:39)

有几种解决方案,最简单的方法是首先尝试运行bundle exec cucumber,看看是否能解决问题。

如果这不起作用,请删除rails3tutorial gemset并重新创建它:

rvm gemset delete rails3tutorial
rvm 1.9.2-p290@rails3tutorial --create

然后运行bundle,希望它会为您安装宝石。使用bundle exec cucumber进行此操作(我几乎总是使用bundle exec运行我的规范和cuke,以便它不会尝试意外加载过时的宝石。)

希望这有效!

更新:再解释一下bundle exec

bundle exec是捆绑器附带的命令,它将在Gemfile的上下文中运行任何其他命令。在这种情况下,您实际上是在告诉它使用Gemfile中的gems运行cucumber命令,而,而不是使用当前可用的所有gem。

例如,如果您之前安装了activesupport 3.2.1,并且您的Gemfile要求activesupport 3.1.0。当发生这种情况时,我相信黄瓜命令本身会引入'activesupport'(可能是通过env.rb中的require 'cucumber/rails'调用),它可以从你的可用中获取任何随机版本的activesupport(比如说它抓住了3.2.1)宝石。在此之后,它决定加载rails环境以开始运行您的功能。当它开始加载您的实际应用程序时,代码会查看您的Gemfile.lock并看到您真正想要的是activesupport 3.1.0,但它无法在新版本之上加载旧版本,因此它会崩溃James Lin粘贴的错误。

这就是为什么,如果你正在使用rvm,为你的单独项目保留单独的gemsets是个好主意,如果你在那个项目上更新你的宝石就删除/重新创建gemsets,这样你就不会保留旧版本的宝石。或者,bundle exec也倾向于解决99%的问题。如果您没有使用rvm,并且有多个项目,那么您可能拥有许多不同gems的许多不同版本,并且您应该始终使用bundle exec来执行诸如执行rake任务,运行cucumer功能和其他单元测试之类的操作等等。

答案 1 :(得分:3)

或者您可以bundle update确保所有宝石插件都是最新版本,它会更新您的Gemfile.lock,因此这两个宝石插件将保持一致。

我想bundle execbundle update之间的区别在于你是否希望bundle提供你的应用程序要求的版本或更新你的应用程序gemfile,以便应用程序不会坚持过时的版本gem安装较新版本时因gem文件而导致问题。

因为发生版本冲突时,通常最好确保系统环境中安装的内容与您的应用Gemfile或锁定文件一致,因为您不希望他们尝试使用旧版本的gem,当有更新的版本可用时,除非你想在应用程序级别使用rvm或类似版本冻结你的gem系统,但同样,当你分发ruby应用程序时,它可能会导致其他机器出现问题。

最后,由于需要分发您的应用,除非较新版本的宝石文件不能与现有应用配合使用,否则我认为它不应该坚持使用陈旧的已知工作版本,除非您总是希望保持安全,这是一个有效的论据。