CucumberTable
A gem which can parse Cucumber-Style String to a table. You can write a table in your test case just like you are using Cucumber. Now it mainly support RSpec.
Installation
Add this line to your application's Gemfile:
gem 'cucumber-table'
And then execute:
$ bundle
Or install it yourself as:
$ gem install cucumber-table
Usage
Examples in RSpec:
describe 'Example 1' do
table :user_info, """
| id | name | email | company | city | country |
| 1 | Bachue | [email protected] | EMC | Shanghai | China |
| 2 | Elicier | [email protected] | Shanghai Normal University | Shanghai | China |
| 3 | Xi Core | unknown | Government of People's Republic of China | Beijing | China |
| 4 | Barack Obama | unknown | Government of United States of America | Washington DC | United States of America |
"""
it 'demos how to use CucumberTable::Table' do
user_info.hashes.should == [{'id' => '1', 'name' => 'Bachue', 'email' => '[email protected]', 'company' => 'EMC', 'city' => 'Shanghai', 'country' => 'China'}, {'id' => '2', 'name' => 'Elicier', 'email' => '[email protected]', 'company' => 'Shanghai Normal University', 'city' => 'Shanghai', 'country' => 'China'}, {'id' => '3', 'name' => 'Xi Core', 'email' => 'unknown', 'company' => 'Government of People\'s Republic of China', 'city' => 'Beijing', 'country' => 'China'}, {'id' => '4', 'name' => 'Barack Obama', 'email' => 'unknown', 'company' => 'Government of United States of America', 'city' => 'Washington DC', 'country' => 'United States of America'}]
end
end
describe 'Example 2' do
it 'demos how to use CucumberTable::Table' do
table :user_info, """
| id | name | email | company | city | country |
| 1 | Bachue | [email protected] | EMC | Shanghai | China |
| 2 | Elicier | [email protected] | Shanghai Normal University | Shanghai | China |
| 3 | Xi Core | unknown | Government of People's Republic of China | Beijing | China |
| 4 | Barack Obama | unknown | Government of United States of America | Washington DC | United States of America |
"""
user_info.hashes.should == [{'id' => '1', 'name' => 'Bachue', 'email' => '[email protected]', 'company' => 'EMC', 'city' => 'Shanghai', 'country' => 'China'}, {'id' => '2', 'name' => 'Elicier', 'email' => '[email protected]', 'company' => 'Shanghai Normal University', 'city' => 'Shanghai', 'country' => 'China'}, {'id' => '3', 'name' => 'Xi Core', 'email' => 'unknown', 'company' => 'Government of People\'s Republic of China', 'city' => 'Beijing', 'country' => 'China'}, {'id' => '4', 'name' => 'Barack Obama', 'email' => 'unknown', 'company' => 'Government of United States of America', 'city' => 'Washington DC', 'country' => 'United States of America'}]
end
end
The Table Object provides a lot of methods, most are from Cucumber::Ast::Table, to operate the table.
Test cases in test/table_spec.rb could help you to understand how to operate the table.
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