Skip to content

DataTable.toTable( List<String[]> ) and/or DataTable.toTable( List<Map<String,String>> )  #433

Closed
@nalbion

Description

@nalbion

The ruby implementation of cucumber allows you to call

Then /^compare table:$/ do | expected_table |
  expected_table.diff!( generate_array_of_hashes() )
end

It doesn't seem to be possible to do this in cucumber-jvm:

@Then("compare table")
public void compare_table( DataTable expectedTable ) {
  expectedTable.diff( generateListArraysOfStrings() ); // List<String[]>
  // or
  expectedTable.diff( generateListOfMaps() );  // List<Map<String,String>>
}

List<String[]>

When the first row of the List contains the column names, DataTable.diff(List) extracts these correctly using topCells().

TableConverter.toTable() ends up with

writer: { columnNames:(as provided in element 0),
               fieldNames: ["string", "string", "string"...]
               fieldValues: [rowN[0], rowN[1]...] }

and then ComplexTypeWriter.getValues() calls

   int index = fieldNames.indexOf(converter.map(columnName));

where columnName is correct, but index is evaluated as -1, so getValues() returns [, , , ,...] so .diff() displays a table of empty strings.

List<Map<String,String>>

TableConverter.toTable() ends up with

writer: { columnNames:(as provided in element 0),
               fieldNames: ["entry", "entry", "entry"...]
               fieldValues: [colName0, row1Value0, colName1, row1Value1...] }

and then ComplexTypeWriter.getValues() calls

   int index = fieldNames.indexOf(converter.map(columnName));

where columnName is correct, but index is evaluated as -1, so getValues() returns [, , , ,...] so .diff() displays a table of empty strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions