2013-05-19 94 views
1

我刚刚将黄瓜安装到新的导轨项目中(第一次将其设置为从头开始),并且在运行所有测试(bundle exec cucumber)但无法找到时运行良好我运行单个功能文件时的任何步骤。我该如何开始调试呢?运行单个功能时,黄瓜找不到步骤

rails (3.2.13) 
cucumber-rails (1.3.1) 
cucumber (>= 1.2.0) 

# file listing 
features/ 
├── campaigns 
│   ├── donating_campaigns.feature 
│   └── viewing_campaigns.feature 
├── step_definitions 
│   └── campaign_steps.rb 
└── support 
    └── env.rb 
+0

我注意到你没有web_steps.rb或path.rb(假设您已将其内容添加到campaign_steps.rb)。运行个别功能时的输出是什么? – kasperite

回答

6

它只能找到功能目录树中相同级别或更低级别的文件。因此,如果您尝试仅运行功能/广告系列/ donating_campaigns.feature中的场景,则无法找到step_definitions目录。

您可以使用--require标志在运行功能之前明确告诉黄瓜包含什么。例如:

bundle exec cucumber --require features/step_definitions features/campaigns/donating_campaigns.feature 
0

我想你可能会误解步骤的定义。在features/step_definitions是你定义你的步骤。所以看起来你有两个包含你将要或已经写好的场景的特性。运行场景,您将看到需要定义的步骤定义。一个用于你的场景的每一行。现在您需要使用Capybara定义您的campaign_steps.rb文件中的步骤。对于一个虚构的例子,

Given /^a user visits the campaign page$/ do 
    visit campaign_path 
end 

When /^the user submits valid campaign information$/ do 
    fill_in "Email", with: @user.email 
    fill_in "Donation", with: @user.donation 
    click_button "donate" 
end 

黄瓜常来与web_steps.rb该定义的许多步骤你。但是,这一点在最近的版本中已经改变并且被忽略了。希望这能让你开始朝正确的方向发展。坚持下去

+0

我在campaign_steps文件中定义了我的步骤。我不知道web_steps中会有什么,但我不需要它,因为我可以在请求cuke运行所有内容时成功运行我的测试。 – reconbot

4

我在我的一个项目中遇到了这个问题。当我比较功能项目的cucumber.yml文件和有问题的项目时,我发现std_optsrerun赋值中的功能文件集-r features。当我将其添加到破碎的项目时,黄瓜可以找到我的步骤定义。

这是我成功的cucumber.yml文件:

<% 
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" 
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" 
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags [email protected] -r features" 
%> 
default: <%= std_opts %> features 
wip: --tags @wip:3 --wip features 
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags [email protected] -r features 

荣誉给这个编码器指着我在正确的方向:http://web.archive.org/web/20121026012412/http://old.thoughtsincomputation.com/posts/cucumber-step-definitions-and-autorequire-hell