我尝试过两个书面指南和一个youtube视频(http://www.youtube.com/watch?v=8ZmawOCDeyo),他们要么跳过一个重要的步骤(或者它只适用于他们),但不适合我。
我创建了以下文件夹结构:
RubyBots\
features\
step_definitions\
creating_a_vehicle_for_an_ai_bot_steps.rb
support\
env.rb
creating_a_vehicle_for_an_ai_bot.feature
vehicle.rb
vehicle_factory.rb
creating_a_vehicle_for_an_ai_bot_steps.rb
的内容:
Given /^I have vehicle factory$/ do
@vehicle_factory = VehicleFactory.new
end
When /^I use it to build a basic vehicle$/ do
@new_vehicle = @vehicle_factory.build
end
Then /^I should have receive a basic vehicle$/ do
#test @new_vechile
end
vehicle_factory.rb
的内容:
class VehicleFactory
def initialize(name)
p name
end
end
env.rb
档案的内容:
require 'vehicle_factory'
require 'vehicle'
我在Cucumber
目录内的CMD窗口内执行RubyBots
(没有参数),我收到以下错误:
no such file to load -- vehicle_factory (LoadError)
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
D:/Code/RubyBots/features/support/env.rb:1:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/rb_support/rb_language.rb:143:in `load'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/rb_support/rb_language.rb:143:in `load_code_file'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime/support_code.rb:176:in `load_file'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime/support_code.rb:78:in `block in load_files!'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime/support_code.rb:77:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime/support_code.rb:77:in `load_files!'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime.rb:137:in `load_step_definitions'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/runtime.rb:39:in `run!'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/cli/main.rb:43:in `execute!'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/lib/cucumber/cli/main.rb:20:in `execute'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/cucumber-1.0.1/bin/cucumber:14:in `<top (required)>'
C:/Ruby192/bin/cucumber:19:in `load'
C:/Ruby192/bin/cucumber:19:in `<main>'
如果从支持目录中删除env.rb
文件,运行Cucumber时会出现以下错误:
Scenario: Using a vehicle factory to build a basic vehicle # Features\creating_a_vehicle_for_an_ai_bot.feature:6
Given I have vehicle factory # Features/creating_a_vehicle_for_an_ai_bot_steps.rb:1
uninitialized constant Object::VehicleFactory (NameError)
./Features/creating_a_vehicle_for_an_ai_bot_steps.rb:2:in `/^I have vehicle factory$/'
Features\creating_a_vehicle_for_an_ai_bot.feature:7:in `Given I have vehicle factory'
When I use it to build a basic vehicle # Features/creating_a_vehicle_for_an_ai_bot_steps.rb:5
Then I should have receive a basic vehicle # Features/creating_a_vehicle_for_an_ai_bot_steps.rb:9
Failing Scenarios:
cucumber Features\creating_a_vehicle_for_an_ai_bot.feature:6 # Scenario: Using a vehicle factory to build a basic vehicle
我已经尝试了所有我能想到的东西而且我的google-fu让我失望了 - 我希望这是非常重要的事情,所以我不会感到尴尬,但很容易修复,所以我可以继续前进! :)
感谢您的帮助!
答案 0 :(得分:1)
您的课程名为VehicleFactory
,但您尝试在creation_a_vehicle_for_an_ai_bot_steps.rb中致电vehicle_factory.new
。
另外,我相信Cucumber期望一个特定的目录结构:
RubyBots/
features/
step_definitions/
creating_a_vehicle_for_an_ai_bot_steps.rb
support/
env.rb
creating_a_vehicle_for_an_ai_bot.feature
您需要适当地从env.rb中获取自己的文件。 Ruby不适合你的任何路径。在my blog post中描述了一种基于符号名称自动要求文件的方法(Rails的方式)(它依赖于ActiveSupport 2.3,但对于当前版本应该类似)。