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

cucumber-expressions: Prefer Java type hint over parameter type #659

Merged
merged 5 commits into from
Aug 11, 2019

Conversation

mpkorstanje
Copy link
Contributor

@mpkorstanje mpkorstanje commented Jul 19, 2019

Summary

When there is a conflict between the type hint from the regular expression
and the method prefer the the parameter type associated with the regular
expression. This ensures we will use the internal/user registered parameter
transformer rather then the default.

Unless the parameter type indicates it is the stronger type hint.

Details

Reasoning:

  1. Pure cucumber expression users will not notice this in either scenario.
  2. Pure regular expression users will benefit because
    BuiltInParameterTransformer can now seamlessly transform any captured
    values. (For all built in types useRegexpMatchAsStrongTypeHint is
    explicitly set to false.)
  3. Regular expression users that define a default transformer have little
    need to define parameter types. The default transformer should be
    sufficiently powerful to meet their needs and will often allow users to
    add custom creation methods e.g. Jacksons @JsonFactory.
  4. Users who mix regular and cucumber expressions may run into conflicts
    when a registered cucumber expression and unregistered happens to
    collide. However this was the situation before this flag was added.
  5. Regular expression users who define custom parameter types do so with
    the expectation that the parameter will be matched. Subverting this
    expectation when the method signature does not match may result in a
    parameter transformer that is unable to convert to the desired type.
    Leaving the user puzzled as to why his transform was ignored.

Motivation and Context

Fixes: #658

Types of changes

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • The change has been ported to Java.
  • The change has been ported to Go.
  • I've added tests for my code.

@aslakhellesoy
Copy link
Contributor

Tip @mpkorstanje - rather than creating a PR prefixed with WIP: , you can mark the PR as a Draft. See https://github.blog/2019-02-14-introducing-draft-pull-requests/

@mpkorstanje
Copy link
Contributor Author

Cool. That's new. Thanks.

When there is a conflict between the type hint from the regular expression
and the method prefer the the parameter type associated with the regular
expression. This ensures we will use the internal/user registered parameter
transformer rather then the default.

Unless the parameter type indicates it is the stronger type hint.

Reasoning:
1. Pure cucumber expression users will not notice this in either scenario.
2. Pure regular expression users will benefit because
   `BuiltInParameterTransformer` can now seamlessly transform any captured
   values. (For all built in types useRegexpMatchAsStrongTypeHint is
   explicitly set to false.)
2. Regular expression users that define a default transformer have little
   need to define parameter types. The default transformer should be
   sufficiently powerful to meet their needs and will often allow users to
   add custom creation methods e.g. Jacksons @JsonFactory.
3. Users who mix regular and cucumber expressions may run into conflicts
   when a registered cucumber expression and unregistered happens to
   collide. However this was the situation before this flag was added.
4. Regular expression users who define custom parameter types do so with
   the expectation that the parameter will be matched. Subverting this
   expectation when the method signature does not match may result in a
   parameter transformer that is unable to convert to the desired type.
   Leaving the user puzzled as to why his transform was ignored.

Fixes: #658
@mpkorstanje mpkorstanje force-pushed the prefer-type-hint--over-parameter-type branch from f1add95 to f90958d Compare August 2, 2019 21:40
@mpkorstanje mpkorstanje changed the title WIP: cucumber-expressions: Prefer Java type hint over parameter type cucumber-expressions: Prefer Java type hint over parameter type Aug 2, 2019
When there is a conflict between the type hint from the regular expression
and the method prefer the the parameter type associated with the regular
expression. This ensures we will use the internal/user registered parameter
transformer rather then the default.

Unless the parameter type indicates it is the stronger type hint.

Reasoning:
1. Pure cucumber expression users will not notice this in either scenario.
2. Pure regular expression users will benefit because
   `BuiltInParameterTransformer` can now seamlessly transform any captured
   values. (For all built in types `useRegexpMatchAsStrongTypeHint` is
   explicitly set to false.)
2. Regular expression users that define a default transformer have little
   need to define parameter types. The default transformer should be
   sufficiently powerful to meet their needs and will often allow users to
   add custom creation methods e.g. Jacksons @JsonFactory.
3. Users who mix regular and cucumber expressions may run into conflicts
   when a registered cucumber expression and unregistered happens to
   collide. However this was the situation before this flag was added.
4. Regular expression users who define custom parameter types do so with
   the expectation that the parameter will be matched. Subverting this
   expectation when the method signature does not match may result in a
   parameter transformer that is unable to convert to the desired type.
   Leaving the user puzzled as to why his transform was ignored.
@mpkorstanje
Copy link
Contributor Author

Implemented Go too.

@mpkorstanje
Copy link
Contributor Author

I'll merge this by the next of next week unless there are any more comments. Then we can bundle it up for the next release of cucumber expressions.

@mpkorstanje mpkorstanje merged commit 21d5254 into master Aug 11, 2019
@mpkorstanje mpkorstanje deleted the prefer-type-hint--over-parameter-type branch August 11, 2019 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cucumber forces Integer type on a \d+ capture group
2 participants