kernel_require.rb:55:in `require': 无法加载此类文件错误 [英] kernel_require.rb:55:in `require': cannot load such file error

查看:31
本文介绍了kernel_require.rb:55:in `require': 无法加载此类文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的是 Ruby 1.9.3 版(尽管我遇到了与 Ruby 2.0.0 相同的问题).在 Windows 7 64 位上.我正在关注The Cucumber Book"并被困在第 7.2 章 - 使用变换删除重复".我的文件夹结构如下:

I'm using Ruby version 1.9.3 at the moment (although I get the same issue with Ruby 2.0.0). On Windows 7 64-bit. I'm following 'The Cucumber Book' and got stuck at the chapter 7.2 - "Removing Duplication with Transforms". My folder structure is as follows:

cash_withdrawal
cash_withdrawalGemfile
cash_withdrawalGemfile.lock
cash_withdrawalfeatures
cash_withdrawalfeaturescash-withdrawal.feature
cash_withdrawalfeaturesstep_definitions
cash_withdrawalfeaturesstep_definitionscash_withdrawal_steps.rb
cash_withdrawalfeaturesstep_definitionslib
cash_withdrawalfeaturesstep_definitionslib
ice_bank.rb
cash_withdrawalfeaturessupport
cash_withdrawalfeaturessupportenv.rb
cash_withdrawalfeaturessupport	ransforms.rb
cash_withdrawalfeaturessupportworld_extensions.rb

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

In my cash_withdrawal_steps.rb file I have:

require 'CAPTURE_CASH_AMOUNT'

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

当我运行 cucumber 我得到:

C:UsersNikita.HarrisonAutomatedTestingcash_withdrawal>黄瓜无法加载此类文件 -- CAPTURE_CASH_AMOUNT (LoadError)C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in要求'C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in要求'C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/step_definitions/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_language.rb:122:inload'C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_language.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:inload_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:ineach' 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:在load_step_definitions'C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:42:in <代码>运行!C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47:在执行!C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/bin/cucumber:13:in<top(必填)>'C:/Ruby193/bin/cucumber:23:inload'C:/Ruby193/bin/cucumber:23:in `'

C:UsersNikita.HarrisonAutomatedTestingcash_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:inload' 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:inload_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:ineach' 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: inload_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: inexecute!' 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 然后运行 ​​require "CAPTURE_CASH_AMOUNT" 我得到这个错误:

And if I run irb then run require "CAPTURE_CASH_AMOUNT" I get this error:

irb(main):006:0> 需要 "CAPTURE_CASH_AMOUNT" LoadError: 无法加载这样的文件——CAPTURE_CASH_AMOUNT来自 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in require'来自 C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:inrequire'来自 (irb):6来自 C:/Ruby193/bin/irb:12:in `'

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:inrequire' from (irb):6 from C:/Ruby193/bin/irb:12:in `'

我尝试了许多修复方法,包括require_relative",但似乎没有任何方法可以解决我的问题.如果我从 cash_withdrawal_steps.rb 文件中删除 require 'CAPTURE_CASH_AMOUNT' 并运行 cucumber,那么我的步骤定义"不会按定义显示:

I've tried many fixes including 'require_relative' and nothing seems to solve my problem. If I remove require 'CAPTURE_CASH_AMOUNT' from the cash_withdrawal_steps.rb file and run cucumber then my 'Step Definition' doesn't show as defined:

C:UsersNikita.HarrisonAutomatedTestingcash_withdrawal>cucumber
Feature: Cash withdrawal

   @test   Scenario: Successful withdrawal from an account in credit #
 featurescash_with drawal.feature:4
     Given I have deposited $100 in my Account               # featurescash_with drawal.feature:5
     When I withdraw $20                                     # features/step_defi nitions/cash_withdrawal_steps.rb:7
     Then $20 should be dispensed                            # features/step_defi nitions/cash_withdrawal_steps.rb:11
     And the balance of my account should be $80             # features/step_defi nitions/cash_withdrawal_steps.rb:15

 1 scenario (1 undefined) 4 steps (3 skipped, 1 undefined) 0m0.006s

 You can implement step definitions for undefined steps with these
 snippets:

 Given(/^I have deposited $(d+) in my Account$/) do |arg1|   pending
 # express the regexp above with the code you wish you had end

如果我添加 require File.join(File.dirname("C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support"), 'support', 'transforms')env.rb 文件并运行 cucumber 我得到:

If I add require File.join(File.dirname("C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support"), 'support', 'transforms') to the env.rb file and run cucumber I get:

 C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support/trans
 forms.rb:1: warning: already initialized constant CAPTURE_CASH_AMOUNT
 Feature: Cash withdrawal

   @test   Scenario: Successful withdrawal from an account in credit #
 featurescash_with drawal.feature:4
     Given I have deposited $100 in my Account               # featurescash_with drawal.feature:5
     When I withdraw $20                                     # features/step_defi nitions/cash_withdrawal_steps.rb:7
     Then $20 should be dispensed                            # features/step_defi nitions/cash_withdrawal_steps.rb:11
     And the balance of my account should be $80             # features/step_defi nitions/cash_withdrawal_steps.rb:15

 1 scenario (1 undefined) 4 steps (3 skipped, 1 undefined) 0m0.013s

 You can implement step definitions for undefined steps with these
 snippets:

 Given(/^I have deposited $(d+) in my Account$/) do |arg1|   pending
 # express the regexp above with the code you wish you had end

我知道我在这里一定做错了什么,但我就是不知道是什么,需要帮助.Gemfile 内容:

I know I must be doing something wrong here but I just can't find out what and need help. Gemfile contents:

# This Gemfile lists all Gems used throughout the book - with versions.
source :rubygems

# Build stuff
gem 'bundler', '1.5.3'
#gem 'rake', '10.1.1'
#gem 'watchr', '0.7'
#gem 'bcat', '0.6.2'

# General stuff
#gem 'aruba', '0.4.11'
gem 'cucumber', '1.3.10', :require => 'cucumber'
gem 'rake', '10.1.1'
gem 'rspec', '2.14.1', :require => 'cucumber'
gem 'rspec-expectations', '2.14.5'
gem 'watir-webdriver', '0.6.7'

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

I think I've included all the information that is needed.

推荐答案

我刚遇到同样的问题,相信是bundler的问题.无论如何,我通过运行解决了这个问题:

I just encountered the same issue, and I believe it's a problem with bundler. In any case, I solved the problem by running:

bundle update
bundle exec ruby <yourfilename.rb>

希望这会有所帮助!

这篇关于kernel_require.rb:55:in `require': 无法加载此类文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆