Skip to content

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

Closed
nalbion opened this Issue Dec 5, 2012 · 3 comments

2 participants

@nalbion
nalbion commented Dec 5, 2012

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.

@nalbion nalbion pushed a commit to nalbion/cucumber-jvm that referenced this issue Dec 5, 2012
Nicholas Albion Implemented fix for issue #433 - DataTable.toTable( List<String[]> ),
toTable( List<Map<String,Object>> ).
Added ArrayOfSingleValueWriter and MapWriter.
bc5c6d9
@nalbion
nalbion commented Dec 5, 2012

Implemented: nalbion@bc5c6d9

...I'm not sure why assertEquals( personTable(), tc.toTable(...) throws an exception...

The ruby implementation also allows columns to be in different orders and allows you to specify whether surplus/missing rows/columns should be allowed.

@aslakhellesoy
Cucumber member

Are you planning to send a pull request for this? If you do, please follow the conventions in DEVELOPERS.md

@aslakhellesoy
Cucumber member

Never mind, just spotted it. Would still be nice if you fixed the formatting.

@aslakhellesoy aslakhellesoy pushed a commit that referenced this issue Dec 5, 2012
DFUK Better table conversion. Closes #433,#434. ff6dca4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.