黄瓜正确的步骤定义文件

时间:2012-03-27 22:05:35

标签: ruby-on-rails cucumber

我有以下步骤:

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.feature user_login.feature

我应该在哪里正确地定义这个定义?

1 个答案:

答案 0 :(得分: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"
相关问题