web-dev-qa-db-fra.com

kernel_require.rb: 55: dans `require ': impossible de charger une telle erreur de fichier

J'utilise actuellement la version 1.9.3 de Ruby (bien que le même problème se pose avec Ruby 2.0.0). Sous Windows 7 64 bits. Je suis 'The Cucumber Book' et je me suis retrouvé coincé au chapitre 7.2 - "Suppression de la duplication avec des transformations". Ma structure de dossier est la suivante:

\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

Dans mon fichier cash_withdrawal_steps.rb, j'ai:

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

Quand je lance cucumber je reçois:

Le concombre C:\Users\Nikita.Harrison\AutomatedTesting\cash_withdrawal> ne peut pas charger ce fichier - 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/g. 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/cucumber/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:in 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' '

Et si j’exécute irb, puis require "CAPTURE_CASH_AMOUNT" j’obtiens cette erreur:

irb (main): 006: 0> require "CAPTURE_CASH_AMOUNT" LoadError: impossible de charger ce fichier - CAPTURE_CASH_AMOUNT à partir de C: /Ruby193/lib/Ruby/site_Ruby/1.9.1/rubygems/core_ext/kernel_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 'à partir de (irb): 6 de C:/Ruby193/bin/irb: 12: dans `'

J'ai essayé de nombreuses corrections, y compris 'require_relative' et rien ne semble résoudre mon problème. Si je supprime require 'CAPTURE_CASH_AMOUNT' du fichier cash_withdrawal_steps.rb et exécute un concombre, ma 'définition de l'étape' ne s'affiche pas comme suit:

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

Si j'ajoute require File.join(File.dirname("C:/Users/Nikita.Harrison/AutomatedTesting/cash_withdrawal/features/support"), 'support', 'transforms') au fichier env.rb et exécute cucumber, je reçois:

 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

Je sais que je dois faire quelque chose de mal, mais je ne peux tout simplement pas trouver quoi et j'ai besoin d'aide. Contenu de 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'

Je pense avoir inclus toute l'information nécessaire.

10
Kita

Je viens de rencontrer le même problème, et je crois que c'est un problème avec bundler. Dans tous les cas, j'ai résolu le problème en lançant:

bundle update
bundle exec Ruby <yourfilename.rb>

J'espère que cela t'aides!

3
zwolfe

Chaque fois que vous installez une nouvelle gemme, vous devez mettre à jour le paquet (comme @zwolfe l’a souligné). Par conséquent, exécutez:

bundle update

Juste après, vous devriez pouvoir exécuter vos scripts Ruby en utilisant simplement:

Ruby <yourRubyScript.rb> ou bundle exec Ruby <yourRubyScript.rb

0
SimionZ

Il semble que j'ai rencontré le même problème avant. Je l'ai corrigé en ajoutant un simple 

require rubygems

avant tout mon besoin de code de ligne.

0
Fabrice31