Kappamaki
Tools for natural, high-level, sophisticated Cucumber steps.
The name comes from the sushi roll filled with pieces of cucumber, which adds naturalness and freshness to a meal.
Usage
Kappamaki provides a number of helper methods that can be used directly in your Cucumber step definitions.
from_sentence
Parses a list of values from a sentence.
Given the restaurant offers cucumber rolls, philadelphia rolls, and avocado rolls
Your step definition would look like this:
Given /^the restaurant offers (.+)$/ do ||
# menu_list is this string:
'cucumber rolls, philadelphia rolls, and avocado rolls'
# Let's parse this into an array
= Kappamaki.from_sentence
# The result, menu, is this array:
['cucumber rolls', 'philadelphia rolls', 'avocado rolls']
# Now we can set up our menu here...
end
attributes_from_sentence
Parses key-value pairs from natural sentences.
When I order a dinner with starter: "miso soup" and entree: "cucumber rolls"
Your step definition would look like this:
When /^I order a dinner with (.+)$/ do |order_items|
# order_items is this string:
'starter: "miso soup" and entree: "cucumber rolls"'
# Let's parse that string using Kappamaki
order_data = Kappamaki.attributes_from_sentence(order_items)
# The result, order_data, is this hash:
{ starter: "miso soup",
entree: "cucumber rolls" }
# now we can set up our order...
create :order, order_data
end
symbolize_keys_deep
Converts the keys of a hash into symbols.
Then I am served these items
| name | count |
| miso soup | 1 |
| cucumber roll | 8 |
Your step definition would look like this:
Then ^I am served these items do |entrees|
entrees.hashes.each do |entree|
# entree is this hash:
{ 'name' => 'miso soup', 'count' => '1' }
# Let's convert the keys to symbols.
Kappamaki.symbolize_keys_deep! entree
# Now entree is this hash:
{ name: 'miso soup', count: '1' }
# Now we can use this hash in places that expect hashes with symbols
expect(order).to include entree
end
end
Installation
- add
gem 'kappamaki'
to your application's Gemfile - run
bundle install
- add
require 'kappamaki'
to your/features/support/env.rb
file
Contributing
- Fork it ( https://github.com/Originate/kappamaki/fork )
- 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 a new Pull Request