Delicious Mock Ruby Tables
Mortadella makes it easy to programmatically build data tables
that can be compared to Cucumber tables
through cucumber_table.diff! mortadella_table
.
You want to do this as much as possible. Cucumber has very powerful built-in facilities to visualize where and how two tables differ.
Oh no, our algorithm selected too many apples!
Installation
- add
gem 'mortadella'
to yourGemfile
- run
bundle
Usage
Mortadella supports horizontal and vertical Cucumber tables.
Horizontal Tables
- In your cucumber spec, define the expected data in table form
Then I have these ingredients
| INGREDIENT | AMOUNT |
| flour | 12 oz |
| butter | 2 oz |
| apples | 3 pc |
- in the step definition for this, build an equivalent Mortadella table with the actual data, and diff the Cucumber table with the expected data against it.
Then /^I have these ingredients$/ do |expected_ingredients|
actual_ingredients = Mortadella::Horizontal.new headers: ['INGREDIENT', 'AMOUNT']
actual_ingredients << ['flour', '12 oz'] # This data should come from your app
actual_ingredients << ['butter', '2 oz'] # This data should come from your app
actual_ingredients << ['apples', '3 pc'] # This data should come from your app
expected_ingredients.diff! actual_ingredients.table
end
you can also dry up repetitive fields for better readability
or filter the columns of your finished table by calling keep_matching_colums
Vertical Tables
- In your cucumber spec, define the expected data in table form
Then my pie conforms to these specs:
| WEIGHT | 2 lbs |
| PORTIONS | 8 |
| CALORIES | 500 |
- in the step definition for this, build an equivalent Mortadella table with the actual data, and diff the Cucumber table with the expected data against it.
Then /^My pie has these metrics:$/ do |expected_metrics|
actual_metrics = Mortadella::Vertical.new
actual_metrics['WEIGHT'] = '2 lbs' # This data should come from your app
actual_metrics['PORTIONS'] = 8 # This data should come from your app
actual_metrics['CALORIES'] = 500 # This data should come from your app
expected_metrics.diff! actual_metrics.table
end
Development
- set up local environment:
bundle install
- run all tests:
bundle exec rake
- run linter only:
rake lint
- run tests only:
rake features
- run linter only:
- publish a new gem:
- update the version in mortadella.gemspec
rake release