When you accept a table in your Cucumber step definition, that table object will have the cryptic type
Cucumber::Ast::Table
Show archive.org snapshot
. Don't immediately call table.raw
to convert it into an array of arrays! Cucumber::Ast::Table
has a lot of useful methods for tasks such as:
table.raw
: Turn the table into an array of arrays
table.hashes
: Convert the table to an array of hashes, where the keys are the table headers from the first row
table.headers
: Return only the first row
table.rows
: Return all but the first row as an array of arrays – you might prefer table.raw
or table.rows_hash
table.rows_hash
: Turn a two-columned table into a hash, where the first column is the keys and the second the values
table.transpose
: Transpose the table (switch rows <-> columns)
Furthermore…