ruby – kernel_require.rb:55:在`require’中:无法加载这样的文件错误

前端之家收集整理的这篇文章主要介绍了ruby – kernel_require.rb:55:在`require’中:无法加载这样的文件错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我使用的是 Ruby 1.9.3版本(尽管我与Ruby 2.0.0相同).在Windows 7 64位.我正在关注“黄瓜书”,并在第7.2章 – “使用变换删除重复”中被卡住.我的文件夹结构如下:
  1. \cash_withdrawal
  2. \cash_withdrawal\Gemfile
  3. \cash_withdrawal\Gemfile.lock
  4. \cash_withdrawal\features
  5. \cash_withdrawal\features\cash-withdrawal.feature
  6. \cash_withdrawal\features\step_definitions
  7. \cash_withdrawal\features\step_definitions\cash_withdrawal_steps.rb
  8. \cash_withdrawal\features\step_definitions\lib
  9. \cash_withdrawal\features\step_definitions\lib\nice_bank.rb
  10. \cash_withdrawal\features\support
  11. \cash_withdrawal\features\support\env.rb
  12. \cash_withdrawal\features\support\transforms.rb
  13. \cash_withdrawal\features\support\world_extensions.rb

在我的cash_withdrawal_steps.rb文件中,我有:

  1. require 'CAPTURE_CASH_AMOUNT'
  2.  
  3. Given /^I have deposited (#{CAPTURE_CASH_AMOUNT}) in my Account$/ do |amount|
  4. my_account.deposit(amount)
  5. my_account.balance.should eq(amount),"Expected the balance to be #{amount} but it was #{my_account.balance}"
  6. end

当我运行黄瓜我得到:

C:\Users\Nikita.Harrison\AutomatedTesting\cash_withdrawal>cucumber
cannot load such file — CAPTURE_CASH_AMOUNT (LoadError)
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in
r equire'
C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in
r equire’
C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/step_definiti
ons/cash_withdrawal_steps.rb:1:in <top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_l
anguage.rb:122:in
load’
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_l
anguage.rb:122:in load_code_file'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime/support
_code.rb:180:in
load_file’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime/support
_code.rb:83:in block in load_files!' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime/support
_code.rb:82:in
each’ C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime/support
_code.rb:82:in load_files!' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:184:
in
load_step_definitions’
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:42:i
n run!'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47:
in
execute!’
C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/bin/cucumber:13:in
<top (re quired)>' C:/Ruby193/bin/cucumber:23:inload’
C:/Ruby193/bin/cucumber:23:in `’

如果我运行irb然后运行需要“CAPTURE_CASH_AMOUNT”我得到这个错误

irb(main):006:0> require “CAPTURE_CASH_AMOUNT” LoadError: cannot load
such file — CAPTURE_CASH_AMOUNT
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_requir
e.rb:55:in require'
from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_requir
e.rb:55:in
require’
from (irb):6
from C:/Ruby193/bin/irb:12:in `’

我已经尝试过许多修复,包括’require_relative’,没有什么似乎可以解决我的问题.
如果我从cash_withdrawal_steps.rb文件删除require’CAPTURE_CASH_AMOUNT’并运行黄瓜,那么我的’步骤定义’不会按照定义显示

  1. C:\Users\Nikita.Harrison\AutomatedTesting\cash_withdrawal>cucumber
  2. Feature: Cash withdrawal
  3.  
  4. @test Scenario: Successful withdrawal from an account in credit #
  5. features\cash_with drawal.feature:4
  6. Given I have deposited $100 in my Account # features\cash_with drawal.feature:5
  7. When I withdraw $20 # features/step_defi nitions/cash_withdrawal_steps.rb:7
  8. Then $20 should be dispensed # features/step_defi nitions/cash_withdrawal_steps.rb:11
  9. And the balance of my account should be $80 # features/step_defi nitions/cash_withdrawal_steps.rb:15
  10.  
  11. 1 scenario (1 undefined) 4 steps (3 skipped,1 undefined) 0m0.006s
  12.  
  13. You can implement step definitions for undefined steps with these
  14. snippets:
  15.  
  16. Given(/^I have deposited \$(\d+) in my Account$/) do |arg1| pending
  17. \# express the regexp above with the code you wish you had end

如果我添加需要File.join(File.dirname(“C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support”),“支持”,“转换”)到env.rb文件并运行黄瓜I得到:

  1. C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support/trans
  2. forms.rb:1: warning: already initialized constant CAPTURE_CASH_AMOUNT
  3. Feature: Cash withdrawal
  4.  
  5. @test Scenario: Successful withdrawal from an account in credit #
  6. features\cash_with drawal.feature:4
  7. Given I have deposited $100 in my Account # features\cash_with drawal.feature:5
  8. When I withdraw $20 # features/step_defi nitions/cash_withdrawal_steps.rb:7
  9. Then $20 should be dispensed # features/step_defi nitions/cash_withdrawal_steps.rb:11
  10. And the balance of my account should be $80 # features/step_defi nitions/cash_withdrawal_steps.rb:15
  11.  
  12. 1 scenario (1 undefined) 4 steps (3 skipped,1 undefined) 0m0.013s
  13.  
  14. You can implement step definitions for undefined steps with these
  15. snippets:
  16.  
  17. Given(/^I have deposited \$(\d+) in my Account$/) do |arg1| pending
  18. \# express the regexp above with the code you wish you had end

我知道我一定在做错事,但是我根本找不到需要帮助的东西.
宝石文件内容

  1. # This Gemfile lists all Gems used throughout the book - with versions.
  2. source :rubygems
  3.  
  4. # Build stuff
  5. gem 'bundler','1.5.3'
  6. #gem 'rake','10.1.1'
  7. #gem 'watchr','0.7'
  8. #gem 'bcat','0.6.2'
  9.  
  10. # General stuff
  11. #gem 'aruba','0.4.11'
  12. gem 'cucumber','1.3.10',:require => 'cucumber'
  13. gem 'rake','10.1.1'
  14. gem 'rspec','2.14.1',:require => 'cucumber'
  15. gem 'rspec-expectations','2.14.5'
  16. gem 'watir-webdriver','0.6.7'

我想我已经包含了所有需要的信息.

解决方法

我刚刚遇到同样的问题,我相信这是捆绑的问题.无论如何,我通过运行解决了这个问题:
  1. bundle update
  2. bundle exec ruby <yourfilename.rb>

希望这可以帮助!

猜你在找的Ruby相关文章