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 certainly create RSpec matchers and use them in your Cucumber steps - I do this fairly frequently. I just place them in features/support/matchers
and they are instantly available to use in my step definitions.
If you wanted to share them with your RSpec tests as well, you may want to extract them to a separate shared_test
type location, and then you could require
that folder in both your Cucumber env.rb file, and your RSpec spec_helper.rb file, then they would be available in both test frameworks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With