Ruby on rails 创建正确的步骤定义文件
我有以下步骤:Ruby on rails 创建正确的步骤定义文件,ruby-on-rails,cucumber,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 在两种不同的功能中:管理员登录功能和用户登录功能 我应该将定义正确放置在哪里?创建一个新文件 可以将其称为flash\u message\u steps.rb或error\u st
Then I should see an error message
定义相同:
Then /^I should see an error message$/ do
page.should have_selector('#flash_alert', text: 'Invalid')
end
在两种不同的功能中:管理员登录功能和用户登录功能
我应该将定义正确放置在哪里?创建一个新文件
可以将其称为flash\u message\u steps.rb
或error\u steps.rb
或任何您喜欢的东西。不过,我建议使用一些通用的方法,称之为admin\u steps.rb
或user\u steps.rb
,实际上没有什么意义。step\u 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"