2012-03-27 93 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