kernel_require.rb:55: в `require': не может загрузить такую ​​ошибку файла

Я использую Ruby версии 1.9.3 на данный момент (хотя у меня возникает та же проблема с Ruby 2.0.0). На Windows 7 64-битная. Я следую "Книге огурцов" и застрял в главе 7.2 - "Удаление дублирования с помощью преобразований". Моя структура папок выглядит следующим образом:

\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

В моем cash_withdrawal_steps.rb файл у меня есть:

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: \ Users \ Nikita.Harrison \ AutomatedTesting \ cash_withdrawal> огурец не может загрузить такой файл - CAPTURE_CASH_AMOUNT (LoadError) C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_require: inre:. 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: в <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загрузить ' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/rb_support/rb_l anguage.rb:122: в 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: в 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каждый ' 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: inC:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/runtime.rb: load_step_definitions:42:i n run!' C:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/lib/cucumber/cli/main.rb:47: inвыполнить! С:/Ruby193/lib/ruby/gems/1.9.1/gems/cucumber-1.3.10/bin/cucumber:13: в <top (re quired)>' C:/Ruby193/bin/cucumber:23:inзагрузить ' C:/Ruby193/bin/ огурец:23: в `'

И если я бегу irb затем беги require "CAPTURE_CASH_AMOUNT" Я получаю эту ошибку:

irb (основной):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: require' from C:/Ruby193/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_requir e.rb:55:inrequire' from (irb):6 из C:/Ruby193/bin/irb:12:in `'

Я перепробовал много исправлений, в том числе 'require_relative', и, похоже, ничего не решило мою проблему. Если я удалю require 'CAPTURE_CASH_AMOUNT' от cash_withdrawal_steps.rb файл и запустить огурец, тогда мое "Определение шага" не отображается, как определено:

C:\Users\Nikita.Harrison\AutomatedTesting\cash_withdrawal>cucumber
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.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 Я получил:

 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

Я знаю, что, должно быть, здесь что-то не так, но я просто не могу понять, что и мне нужно помочь. Содержание Gemfile:

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

Я думаю, что я включил всю информацию, которая необходима.

3 ответа

Я только что столкнулся с той же проблемой, и я считаю, что это проблема с упаковщиком. В любом случае я решил проблему, запустив:

bundle update
bundle exec ruby <yourfilename.rb>

Надеюсь это поможет!

Кажется, я сталкивался с той же проблемой раньше. Я исправил это, добавив простой

require rubygems

прежде чем все мои требуют строки кода.

Всякий раз, когда вы устанавливаете новый гем, вам нужно обновить пакет (как указывал @zwolfe). Следовательно, запустите:

bundle update

Сразу после этого вы сможете запускать скрипты на Ruby, используя просто:

ruby <yourRubyScript.rb>или жеbundle exec ruby <yourRubyScript.rb

Другие вопросы по тегам