CucumberTricks
Cucumber step definition dsl extension to easily define more readable steps.
Installation
Add this line to your application's Gemfile:
gem 'cucumber_tricks', :require => false
And then execute:
$ bundle
Or install it yourself as:
$ gem install cucumber_tricks
Usage
Detailed usage examples can be found on relish
Requiring the files
Add `require 'cucumber_tricks' from every steps definition file where you use it. This will make cucumber work in normal mode as well as in dry-run mode.
Use pronouns to reference previously introduced items
foo.feature
Given the tool 'screwdriver'
When this tool is used
steps.rb
A_TOOL = NameOrPronounTransform('tool', 'hammer')
Given /^(#{A_TOOL})$/ do |tool|
...
end
Use the same step implementation to handle an inline arg as a 1-cell table
steps.rb
GivenEither /^the dog named "(.*)"$)$/,
/^the following dogs$/ do |dogs_table|
...
end
foo.feature
Given the dog "Rolphy"
...
Given the following dogs
| Rex |
| King |
| Volt |
Add default values to the hashes of a table
foo.feature
Given the following dogs
| names | color |
| Rex | white |
| King | Sand |
steps.rb
Given /^the following dogs$$/ do |dogs|
hashes = dogs.hashes_with_defaults('names', 'tail' => 'wagging', 'smell' => 'not nice')
# hashes.each do |hash|
# expect(hash['smell']).to eq('not nice')
# end
...
end
Define named lists from a table
foo.feature
Given the following dishes
| Spaghetti Bolognaise | => | Spaghetti | Bolognaise sauce | | |
| Burger | => | Bread | Meat | Salad | Ketchup |
steps.rb
Given /^the following dishes$$/ do |dishes|
name_2_dishes = dishes.hash_2_lists
# expect(name_2_dishes['Burger']).to eq(['Bread','Meat','Salad','Ketchup'])
...
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request