-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to configure a DataTableType for a List<List<String>> type #1884
Comments
The use case for data table transformers is transforming table to types other then The problem you're running into is that registering a function Looking at the implementation of the DataTableTypeRegistry one solution would be to make the predefined string and object data table types override-able. For the primitives however we have double registrations. But I think it'd be okay not to make it possible to . Semantically speaking trying to parse white-space doesn't make much sense there. |
So the use case to cover would be Feature: Whitespace
Scenario: Whitespace in a table
Given a blank value
| key | value |
| a | [blank] | @Given("A blank value")
public void given_a_blank_value(Map<String, String> map){
// map contains { "key":"a", "value": ""}
}
@DataTableType(replaceWithEmptyString = "[blank]")
public String listOfStringListsType(String cell) {
return cell;
} |
Yes, I think that make sense - so any step definition where the text in the cell is being parsed into a string (such as |
This enables the following in Cucumber-JVM: ```feature Feature: Whitespace Scenario: Whitespace in a table Given a blank value | key | value | | a | [blank] | ``` ```java @given("A blank value") public void given_a_blank_value(Map<String, String> map){ // map contains { "a": ""} } @DataTableType(replaceWithEmptyString = "[blank]") public String listOfStringListsType(String cell) { return cell; } ``` Note that this only applies to `String` and `Object` the other build in types can not be redefined. Though this could be considered if a clear usecase is presented. See: cucumber/cucumber-jvm#1884
This enables the following in Cucumber-JVM: ```feature Feature: Whitespace Scenario: Whitespace in a table Given a blank value | key | value | | a | [blank] | ``` ```java @given("A blank value") public void given_a_blank_value(Map<String, String> map){ // map contains { "key":"a", "value": ""} } @DataTableType(replaceWithEmptyString = "[blank]") public String listOfStringListsType(String cell) { return cell; } ``` Note that this only applies to `String` and `Object` the other build in types can not be redefined. Though this could be considered if a clear usecase is presented. See: cucumber/cucumber-jvm#1884
That is correct. You may find it interesting to read the data table libraries design documentation. https://github.com/cucumber/cucumber/tree/master/datatable |
Can't promise any delivery dates but you are ofcourse free to interpret the current release frequency. |
Fantastic! Thanks for all the help and the quick response too :) |
…ed (#885) This enables the following in Cucumber-JVM: ```feature Feature: Whitespace Scenario: Whitespace in a table Given a blank value | key | value | | a | [blank] | ``` ```java @given("A blank value") public void given_a_blank_value(Map<String, String> map){ // map contains { "key":"a", "value": ""} } @DataTableType(replaceWithEmptyString = "[blank]") public String listOfStringListsType(String cell) { return cell; } ``` Note that this only applies to `String` and `Object` the other build in types can not be redefined. Though this could be considered if a clear usecase is presented. See: cucumber/cucumber-jvm#1884
…ed (#885) This enables the following in Cucumber-JVM: ```feature Feature: Whitespace Scenario: Whitespace in a table Given a blank value | key | value | | a | [blank] | ``` ```java @given("A blank value") public void given_a_blank_value(Map<String, String> map){ // map contains { "key":"a", "value": ""} } @DataTableType(replaceWithEmptyString = "[blank]") public String listOfStringListsType(String cell) { return cell; } ``` Note that this only applies to `String` and `Object` the other build in types can not be redefined. Though this could be considered if a clear usecase is presented. See: cucumber/cucumber-jvm#1884
…ed (#885) This enables the following in Cucumber-JVM: ```feature Feature: Whitespace Scenario: Whitespace in a table Given a blank value | key | value | | a | [blank] | ``` ```java @given("A blank value") public void given_a_blank_value(Map<String, String> map){ // map contains { "key":"a", "value": ""} } @DataTableType(replaceWithEmptyString = "[blank]") public String listOfStringListsType(String cell) { return cell; } ``` Note that this only applies to `String` and `Object` the other build in types can not be redefined. Though this could be considered if a clear usecase is presented. See: #1884
Description
I've been unable to configure a DataTableType for the type
List<List<String>>
. When attempting to configure a@DataTableType(replaceWithEmptyString = "[none]")
for a List of Lists of Strings, I get the following exception:This doesn't occur when attempting to configure a DataTableType for a
List<String>
or aList<Map<String, String>>
Context & Motivation
I'm currently upgrading a project that uses Cucumber 2 to Cucumber 5. The project has made heavy use of the Datatable asLists method, and many of the datatables have empty values, that were previously parsed as an empty string, but are now being parsed as null (due to the changes associated with this issue: #1617).
Because of the kind comparisons we are performing in the project, we want to be able to keep having empty strings returned from our datatables, and so I was looking to use (#1857) as a way to restore this, replacing the empty datatable cells in our feature files with [none] and configuring DataTableTypes for
List<String>
,List<Map<String, String>>
andList<List<String>>
which would all use replaceWithEmptyString with "[none]".I'm not 100% confident that this is actually the correct approach to go about doing this, but nothing else I've tried so far seems to work for my use case, and the pattern appears to work fine for both the
List<String>
andList<Map<String, String>>
types (as can be seen in the attached sample project), so it's unclear to me why this doesn't work forList<List<String>>
If I'm doing this all wrong, it would be great to know what the best way to achieve the behaviour I want is!To Reproduce
I've attached a minimal sample project that reproduces the issue when running the maven test target.
Alternatively you can reproduce this by setting up a DataTableType:
And then attempting to run a cucumber feature
My Environment
Sample project
cucumber-datatabletype-test.zip
The text was updated successfully, but these errors were encountered: