2013-05-19 90 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