Important
This gem is no longer maintained. Use Mandoline to migrate your E2E tests from Cucumber to RSpec.
Overridable step definitions for Cucumber
Cucumber raises an error if more than one step definitions match a step.
This gem provides a way to mark step definitions as overridable, meaning that they can always be overshadowed by a more specific version without raising an error.
Examples
Marking step definitions as overridable
To mark a step definition as overridable, call #overridable on the definition object:
Given /^there is a movie with a (.*?) tone$/ do
...
end.overridable
Given /^there is a movie with a funny tone$/ do
...
endThe following step will now no longer raise Cucumber::Ambiguous:
Given there is a movie with a funny toneIf a step matches more than one non-overridable steps, Cucumber will still raise Cucumber::Ambiguous.
Defining priorities
You can define priorities for overridable steps by passing an numeric :priority option to #overridable:
Given /^there is a movie with a (.*?) tone$/ do
...
end.overridable(priority: 1)
Given /^there is a movie with a (sad|upbeat|disturbing) tone$/ do
...
end.overridable(priority: 5)A higher priority wins the match.
A non-overridable step will always win over an overridable step regardless of its priority.
Supported Cucumber versions
cucumber_priority is tested against Cucumber 1.3, 2.4, 3.0, 3.1, 4.1, 5.3, 9.2 and 10.1.
Installation
In your Gemfile say:
gem 'cucumber_priority'Now run bundle install and restart your server.
Development
There are tests in spec. We only accept PRs with tests. To run tests:
- Install Ruby 2.5.3
- Install development dependencies using
bundle install - Run tests using
bundle exec rspec
We recommend to test large changes against multiple versions of Ruby and multiple dependency sets. Supported combinations are configured in .github/workflows/test.yml. We provide some rake tasks to help with this:
-
Run tests for a specific version of Ruby, Bundler and Gemfile:
rbenv shell 3.4.1 export BUNDLE_GEMFILE=Gemfile.cucumber-9.2 bundle _2.6.3_ install bundle _2.6.3_ exec rake current_rspec
-
Install development dependencies using
bundle matrix:install -
Run tests using
bundle matrix:spec -
Run tests for all rubies:
for version in "2.5.3" "2.6.6" "2.7.2" "3.2.0" "3.3.6" "3.4.1"; do rbenv shell $version && bundle install && bundle exec rake matrix:install && bundle exec rake matrix:spec; done
Note that we have configured GitHub Actions to automatically run tests in all supported Ruby versions and dependency sets after each push. We will only merge pull requests after a green workflow build.
If you would like to contribute:
- Fork the repository.
- Push your changes with passing specs.
- Send us a pull request.
I'm very eager to keep this gem leightweight and on topic. If you're unsure whether a change would make it into the gem talk to me beforehand.
Credits
Henning Koch from makandra