Skip to content
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

Use dedicated DocStringTypeRegistry for doc string transforms #1705

Closed
mpkorstanje opened this issue Jul 21, 2019 · 0 comments
Closed

Use dedicated DocStringTypeRegistry for doc string transforms #1705

mpkorstanje opened this issue Jul 21, 2019 · 0 comments
Labels
⚡ enhancement Request for new functionality
Milestone

Comments

@mpkorstanje
Copy link
Contributor

mpkorstanje commented Jul 21, 2019

Summary

Cucumber uses the DatatTableTypeRegistry to convert doc strings. This is rather confusing and ignores the type provided with the doc string.

Motivation & Context

With #1458 and #851 implemented it will be quite hard to explain how doc strings are converted. So it would be better to do it properly.

Current Behavior

Given some gherkin

Given a doc string
"""json
{hello:"world"}
"""

And a step definition:

@Given("a doc string")
public void a_doc_string(JsonNode json){

}

In the StepExpressionFactory Cucumber will try to transform this string into JSON by turning the docstring into a 1x1 table and using the DataTableTypeRegistry to convert it to an object of the right target type.

DocStringTransformer<?> docStringTransform = new DocStringTransformer<Object>() {
    @Override
    public Object transform(String docString) {
        Type targetType = tableOrDocStringType.resolve();
        if (Object.class.equals(targetType)) {
            return docString;
        }

        List<List<String>> raw = singletonList(singletonList(docString));
        return DataTable.create(raw, StepExpressionFactory.this.tableConverter).convert(targetType, transpose);
    }
};

Expected Behavior

Cucumber uses a DocStringTypeRegistry in which transformations for each document type can be registered or where a default doc string transformer (document, type) -> Object can be registered.

@mpkorstanje mpkorstanje added Data Tables ⚡ enhancement Request for new functionality labels Jul 21, 2019
@mpkorstanje mpkorstanje added this to the 5.x.x milestone Jul 21, 2019
rasklaad pushed a commit that referenced this issue Aug 19, 2019
Use dedicated DocStringTypeRegistry for doc string transforms
@mpkorstanje mpkorstanje modified the milestones: 5.x.x, 5.0.0 Sep 12, 2019
mpkorstanje pushed a commit that referenced this issue Sep 9, 2021
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

1 participant