kernel_require.rb:55:in `require': 无法加载该文件错误

9 浏览
0 Comments

kernel_require.rb:55:in `require': 无法加载该文件错误

我目前正在使用 Ruby 1.9.3 版本(尽管我也在 Ruby 2.0.0 版本上遇到了相同的问题)。我的操作系统是 Windows 7 64 位。我正在按照《Cucumber 书籍》的章节 7.2 - \"使用转换去除重复\" 进行操作。我的文件夹结构如下:\n

\cash_withdrawal
\cash_withdrawal\Gemfile
\cash_withdrawal\Gemfile.lock
\cash_withdrawal\features
\cash_withdrawal\features\cash-withdrawal.feature
\cash_withdrawal\features\step_definitions
\cash_withdrawal\features\step_definitions\cash_withdrawal_steps.rb
\cash_withdrawal\features\step_definitions\lib
\cash_withdrawal\features\step_definitions\lib\nice_bank.rb
\cash_withdrawal\features\support
\cash_withdrawal\features\support\env.rb
\cash_withdrawal\features\support\transforms.rb
\cash_withdrawal\features\support\world_extensions.rb

\n在我的 cash_withdrawal_steps.rb 文件中,我有以下内容:\n

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

\n当我运行 cucumber 时,出现以下错误:\n

\nC:\\Users\\Nikita.Harrison\\AutomatedTesting\\cash_withdrawal>cucumber\n cannot load such file -- CAPTURE_CASH_AMOUNT (LoadError)\n C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in\n

r equire'
  C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require.rb:55:in
  

r equire\'\n C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/step_definiti\n ons/cash_withdrawal_steps.rb:1:in

'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_l
  anguage.rb:122:in

load\'\n C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_l\n 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\n _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\n _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\'\n C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime.rb:42:i\n n

run!'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47:
  in

execute!\'\n C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/bin/cucumber:13:in\n \' C:/Ruby193/bin/cucumber:23:inload\'\n C:/Ruby193/bin/cucumber:23:in `\'\n

\n如果我在 cash_withdrawal_steps.rb 文件中移除 require \'CAPTURE_CASH_AMOUNT\' 并运行 cucumber,则我的 \'Step Definition\' 不会显示已定义:\nC:\\Users\\Nikita.Harrison\\AutomatedTesting\\cash_withdrawal>cucumber\nFeature: Cash withdrawal\n @test Scenario: Successful withdrawal from an account in credit #\n features\\cash_with drawal.feature:4\n Given I have deposited $100 in my Account # features\\cash_with drawal.feature:5\n When I withdraw $20 # features/step_defi nitions/cash_withdrawal_steps.rb:7\n Then $20 should be dispensed # features/step_defi nitions/cash_withdrawal_steps.rb:11\n And the balance of my account should be $80 # features/step_defi nitions/cash_withdrawal_steps.rb:15\n 1 scenario (1 undefined) 4 steps (3 skipped, 1 undefined) 0m0.006s\n You can implement step definitions for undefined steps with these\n snippets:\n Given(/^I have deposited \\$(\\d+) in my Account$/) do |arg1| pending\n \\# express the regexp above with the code you wish you had end\n\n如果我在 env.rb 文件中添加 require File.join(File.dirname(\"C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support\"), \'support\', \'transforms\') 并运行 cucumber,则会出现以下错误:\n

 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 #
 features\cash_with drawal.feature:4
     Given I have deposited $100 in my Account               # features\cash_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

\n我知道我一定做错了什么,但我无法找到问题所在,需要帮助。 \nGemfile 内容如下:\n

# 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'

\n我想我已经提供了所有需要的信息。

0
0 Comments

当你安装一个新的gem时,你需要更新bundle(如上所述)。

因此,运行:

bundle update

然后你就能够使用以下方式运行你的Ruby脚本:

ruby <yourRubyScript.rb>

或者

bundle exec ruby <yourRubyScript.rb

然而,有时候在运行Ruby脚本时,可能会遇到类似于"cannot load such file"的错误。这个错误的出现通常是因为在脚本中使用了某个gem,但是该gem并没有正确地被加载。

具体来说,这个错误可能是由于在kernel_require.rb文件的第55行处发生了问题。这个文件是Ruby的内核文件,负责处理脚本中的require语句。当执行require语句时,Ruby会尝试加载指定的文件。然而,在这种情况下,Ruby无法找到需要加载的文件,因此会抛出一个错误。

要解决这个问题,有两个常见的方法。首先,你可以尝试运行bundle update命令,以确保所有的gem都是最新的版本。这将确保所有的依赖关系都被正确地加载。

如果更新bundle后仍然出现问题,你可以检查你的脚本中的require语句。确保你正确地指定了要加载的gem,并且gem的名称与实际安装的gem名称一致。有时候,gem的名称可能与脚本中使用的名称不完全相同,导致加载失败。

通过更新bundle和检查require语句,你应该能够解决"cannot load such file"错误,并成功运行你的Ruby脚本。

0
0 Comments

最近遇到了一个问题,我在使用require加载文件时出现了一个错误。错误信息是(kernel_require.rb:55:in `require': cannot load such file)。经过一番研究,我发现了这个问题出现的原因以及解决方法。我尝试在所有的require行代码之前添加了一行简单的代码require rubygems,问题得到了解决。

谢谢你提供的信息,我也尝试了这个方法,但仍然没有解决问题。后来我在我的MacBook Pro上进行了相同的设置,却没有出现任何问题。当我找到解决方法时,我会把它发布出来。但目前我仍然在Windows上遇到了这个问题,而在Mac上却没有。

总结一下,这个问题的原因是无法加载所需的文件,解决方法是在所有的require行代码之前添加require rubygems。希望这篇文章对遇到同样问题的人有所帮助。

0
0 Comments

在我的使用过程中,我遇到了同样的问题,我相信这是一个与bundler有关的问题。不管怎样,我通过运行以下命令解决了这个问题:

bundle update
bundle exec ruby 

希望这能帮到你!

0