I’m reading the new version of “Rails Tutorial” by Michael Hartl and, since I’m pretty fond in BDD with Cucumber, I found myself concerned about what the author points out here: http://ruby.railstutorial.org/chapters/sign-in-sign-out?version=3.2#sec:rspec_custom_matchers
In few words the main hassle with Cucumber is that it’s impossible to DRY implementation-dependent tests like this:
Then /^he should see an error message$/ do
page.should have_selector('div.alert.alert-error', text: 'Invalid')
end
writing RSpec custom matchers like this:
RSpec::Matchers.define :have_error_message do |message|
match do |page|
page.should have_selector('div.alert.alert-error', text: message)
end
end
Because such a custom matcher must be put in spec/support/utilities.rb and can be called from RSpec integration tests but not from Cucumber step definitions.
Are you positive / what you think about it?
Thank you.
You can put implementation-dependent or reusable methods, locators to Cucumber World.
Example for your scenario:
Here are some articles that refer to this approach: