2014-02-17 51 views
10

我現在使用的是Ruby 1.9.3版本(雖然我遇到了Ruby 2.0.0的相同問題)。在Windows 7 64位上。我正在關注「黃瓜書」,並陷入了第7.2章「用變換去除重複」中。我的文件夾結構如下:kernel_require.rb:55:在'require'中:無法加載這樣的文件錯誤

\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>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:in load' C:/Ruby193/bin/cucumber:23:in `'

如果我跑irb然後運行require "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'和運行黃瓜然後我的「步驟定義」不顯示的定義:

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' 

我想我已經包含所需要的所有信息。

回答

0

看來我以前遇到同樣的問題。我通過添加一個簡單的

require rubygems 

之前所有我需要的行代碼。

+2

感謝您的信息,試過這個,它仍然沒有工作。從那時起,我在MacBook Pro上完成了完全相同的設置,並且這種方式沒有任何問題......當我找到解決方案時,我會發布它,但現在我仍然堅持在Windows上的這個問題,但不是蘋果電腦。 – Kita

2

我剛剛遇到同樣的問題,我相信這是捆綁器的問題。無論如何,我通過跑步解決了這個問題:

bundle update 
bundle exec ruby <yourfilename.rb> 

希望這有助於!

相關問題