2012-03-27 124 views
3

我有以下步驟:黃瓜正確步驟的定義文件

Then I should see an error message 

具有相同的定義:

Then /^I should see an error message$/ do 
    page.should have_selector('#flash_alert', text: 'Invalid') 
end 
在兩個不同的特徵

admin_sign_in.featureuser_login.feature

我應該在哪裏正確放置定義?

回答

3

創建一個新文件。

稱之爲flash_message_steps.rberror_steps.rb或其他你喜歡的東西。我會建議一些通用的,雖然稱它admin_steps.rbuser_steps.rb真的沒有意義。 step_definitions文件夾中的所有文件都是自動加載的。只要確定一次,因爲同一步驟的重複定義會引起模糊性錯誤。

我還建議讓你一步更通用的,是這樣的:

Then /^I should see an error message containing "([^\"]*)"$/ do |message| 
    page.should have_selector('#flash_alert', text: message) 
end 

然後,您可以使用相同的定義,測試多個錯誤:

Then I should see an error message containing "Invalid" 

Then I should see an error message containing "You must sign in first" 
+0

謝謝你很好的解釋。 – 2012-03-28 07:44:50