Cucumber 找不到已安装的 gem

发布于 2024-08-26 08:51:11 字数 4591 浏览 3 评论 0原文

environment/cucumber.rb:

...
# gem dependencies
config.gem 'cucumber-rails',   :lib => false, :version => '>=0.3.0' unless File.directory?(File.join(Rails.root, 'vend
config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vend
config.gem 'webrat',           :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vend

config.gem 'spork',            :lib => false, :version => '>=0.7.5' unless File.directory?(File.join(Rails.root, 'vend

config.gem 'factory_girl', :source => 'http://gemcutter.org'
config.gem 'selenium-client', :lib => false
config.gem 'Selenium', :lib => false
config.gem 'rspec', :lib => 'spec'
config.gem 'rspec-rails', :lib => 'spec/rails'
config.gem 'test-unit', :lib => false

运行 cucumber 会出现缺少 gem 的错误:

artem:~/projects/food4feed (master)$ cucumber
...
no such file to load -- Selenium
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rspec-rails-1.3.2/lib/spec/rails.rb:13:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/rails/gem_dependency.rb:208:in `load'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `block in load_gems'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `each'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `load_gems'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:169:in `process'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
/home/artem/projects/food4feed/config/environment.rb:9:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/projects/food4feed/features/support/env.rb:12:in `block in <top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/spork-0.8.1/lib/spork.rb:23:in `prefork'
/home/artem/projects/food4feed/features/support/env.rb:10:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/rb_support/rb_language.rb:124:in `load_code_file'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:85:in `load_code_file'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:77:in `block in load_code_files'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `each'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `load_code_files'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:48:in `execute!'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:20:in `execute'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/bin/cucumber:8:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `load'
/home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `<main>'
Missing these required gems:
  selenium-client
  Selenium
  rspec-rails

You're running:
  ruby 1.9.1.378 at /home/artem/.rvm/rubies/ruby-1.9.1-p378/bin/ruby
  rubygems 1.3.5 at /home/artem/.rvm/gems/ruby-1.9.1-p378, /home/artem/.rvm/gems/ruby-1.9.1-p378%global

所有 gem 显然都在那里:

artem:~/projects/food4feed (master)$ gem list | egrep "elenium|rspec|test-unit"
rspec (1.3.0)
rspec-rails (1.3.2)
Selenium (1.1.14)
selenium-client (1.2.18)
test-unit (2.0.7)

更令人困惑的部分是它只抱怨某些 gem。 factory_girlrspec 不会引起问题。

知道发生了什么事吗?


我的环境:

  • Rails 2.3.5
  • cucumber (0.6.3)
  • cucumber-rails (0.3.0)

environment/cucumber.rb:

...
# gem dependencies
config.gem 'cucumber-rails',   :lib => false, :version => '>=0.3.0' unless File.directory?(File.join(Rails.root, 'vend
config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vend
config.gem 'webrat',           :lib => false, :version => '>=0.7.0' unless File.directory?(File.join(Rails.root, 'vend

config.gem 'spork',            :lib => false, :version => '>=0.7.5' unless File.directory?(File.join(Rails.root, 'vend

config.gem 'factory_girl', :source => 'http://gemcutter.org'
config.gem 'selenium-client', :lib => false
config.gem 'Selenium', :lib => false
config.gem 'rspec', :lib => 'spec'
config.gem 'rspec-rails', :lib => 'spec/rails'
config.gem 'test-unit', :lib => false

Running cucumber gives missing gems error:

artem:~/projects/food4feed (master)$ cucumber
...
no such file to load -- Selenium
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rspec-rails-1.3.2/lib/spec/rails.rb:13:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/rails/gem_dependency.rb:208:in `load'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `block in load_gems'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `each'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:307:in `load_gems'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:169:in `process'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
/home/artem/projects/food4feed/config/environment.rb:9:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/projects/food4feed/features/support/env.rb:12:in `block in <top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/spork-0.8.1/lib/spork.rb:23:in `prefork'
/home/artem/projects/food4feed/features/support/env.rb:10:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/polyglot-0.3.0/lib/polyglot.rb:65:in `require'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/rb_support/rb_language.rb:124:in `load_code_file'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:85:in `load_code_file'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:77:in `block in load_code_files'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `each'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/step_mother.rb:76:in `load_code_files'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:48:in `execute!'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/lib/cucumber/cli/main.rb:20:in `execute'
/home/artem/.rvm/gems/ruby-1.9.1-p378/gems/cucumber-0.6.3/bin/cucumber:8:in `<top (required)>'
/home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `load'
/home/artem/.rvm/gems/ruby-1.9.1-p378/bin/cucumber:19:in `<main>'
Missing these required gems:
  selenium-client
  Selenium
  rspec-rails

You're running:
  ruby 1.9.1.378 at /home/artem/.rvm/rubies/ruby-1.9.1-p378/bin/ruby
  rubygems 1.3.5 at /home/artem/.rvm/gems/ruby-1.9.1-p378, /home/artem/.rvm/gems/ruby-1.9.1-p378%global

All gems are obviously there:

artem:~/projects/food4feed (master)$ gem list | egrep "elenium|rspec|test-unit"
rspec (1.3.0)
rspec-rails (1.3.2)
Selenium (1.1.14)
selenium-client (1.2.18)
test-unit (2.0.7)

Even more confusing part is that it only complains about certain gems. factory_girl and rspec don't cause problems.

Any idea what is going on?


My environment:

  • Rails 2.3.5
  • cucumber (0.6.3)
  • cucumber-rails (0.3.0)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

祁梦 2024-09-02 08:51:11

好吧,我想通了(在 aslakhellesoy 的帮助下,谢谢!)。当 Cucumber 说缺少这些必需的 gems 时,它也可能意味着无法加载这些必需的 gems。这增加了所有可能的错误。

在这种情况下,gems 名称(rspec-rails 除外)与 require 的相应库文件不匹配。例如,应该有 :lib =>; 'selenium' 添加到 config.gem 'selenium-client'

至于 rspec-rails,由于测试单元版本错误而无法加载: Gem::LoadError: RubyGem version error: test-unit(2.0.7 not = 1.2.3) 。如果 cucumber 首先报告此错误(我从控制台要求 rspec-rails 得到它),那将会有很大帮助。

Ok, I figured it (with the help of aslakhellesoy, thanks!). When cucumber says Missing these required gems it may also mean Can't load these required gems. Which adds the whole spectrum of possible errors.

In this case, gems names (apart from rspec-rails) didn't match corresponding library files to require. For instance, there should have been :lib => 'selenium' added to config.gem 'selenium-client'.

As for rspec-rails, it was failing to load because of the wrong version of test-unit: Gem::LoadError: RubyGem version error: test-unit(2.0.7 not = 1.2.3). It would have helped a lot if cucumber reported this error in the first place (I got it from requiring rspec-rails from console).

裂开嘴轻声笑有多痛 2024-09-02 08:51:11

您的 config/environment.rb 或 features/support/env.rb 文件中是否有 require 'test-unit' ?

如果你这样做,那就错了。 test-unit gem 没有 test-unit.rb 文件,因此 require 'test-unit' 总是会失败。尝试删除 require 行,或者至少尝试要求正确的文件:

require 'test/unit'

我不确定您为什么要尝试显式加载测试单元。

Do you have require 'test-unit' somewhere in your config/environment.rb or features/support/env.rb file?

If you do, that's wrong. The test-unit gem doesn't have a test-unit.rb file, so require 'test-unit' will always fail. Try to remove the require line, or at least try to require the correct file:

require 'test/unit'

I'm not sure why you're trying to explicitly load test-unit anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文