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
    .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 |
    """

    .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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request