Correct cucumber definition file
I have the next step:
Then I should see an error message
with identical definition:
Then /^I should see an error message$/ do
page.should have_selector('#flash_alert', text: 'Invalid')
end
in two different functions: admin_sign_in.feature and user_login.feature .
Where should I place the definition correctly?
source to share
Create a new file.
Call it something like flash_message_steps.rb
or error_steps.rb
or whatever you like. I would suggest something general, but it doesn't make sense to call it admin_steps.rb
or user_steps.rb
. All files in the folder are step_definitions
automatically downloaded. Just remember to define it once only if duplicate definitions for the same step will cause an ambiguity error.
I would also recommend making your step more general, something like:
Then /^I should see an error message containing "([^\"]*)"$/ do |message|
page.should have_selector('#flash_alert', text: message)
end
Then you can use the same definition to check for multiple errors:
Then I should see an error message containing "Invalid"
Then I should see an error message containing "You must sign in first"
source to share