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

defineParameterType cannot handle regexp with groups for regexp step definition #219

Closed
aslakhellesoy opened this issue Jun 7, 2017 · 2 comments
Labels
🐛 bug Defect / Bug

Comments

@aslakhellesoy
Copy link
Contributor

From @yaronassa on June 7, 2017 19:32

On CucumberJS 2.2:
TL;DR - When working with RegExp steps, parameters with inner groups aren't processed by the matching parameter types.

Steps to reproduce (exact code provided below):

  1. Define a step using regexp with a parameter that includes inner non-capturing groups.
  2. Define a parameter type tracking this parameter.

The parameter type transform function doesn't execute.

Reproduce with the following scenarios (to be added to /features/parameter_types.feature):

Demonstrate the bug itself (will fail):

Scenario: transform regexp with groups
    Given a file named "features/demo_steps.feature" with:
      """
      Feature: a feature
        Scenario: a scenario
          Given a demo step
      """
    Given a file named "features/step_definitions/my_steps.js" with:
      """
      import assert from 'assert'
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({Given}) => {
        Given(/a (demo(?:nstration)?) step/, function(param) {
          assert.equal(param, 'DEMO')
        })
      })
      """
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /demo(?:nstration)?/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a demo step" has status "passed"

Demonstrate the bug doesn't occur without capture groups (will pass):

Scenario: transform without groups
    Given a file named "features/demo_steps.feature" with:
      """
      Feature: a feature
        Scenario: a scenario
          Given a demo step
      """
    Given a file named "features/step_definitions/my_steps.js" with:
      """
      import assert from 'assert'
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({Given}) => {
        Given(/a (demo|demonstration) step/, function(param) {
          assert.equal(param, 'DEMO')
        })
      })
      """
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /demo|demonstration/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a demo step" has status "passed"

Demonstrate the bug doesn't occur with cucumber expressions (will pass):

 Scenario: transform expression with groups
    Given a file named "features/demo_steps.feature" with:
      """
      Feature: a feature
        Scenario: a scenario
          Given a demo step
      """
    Given a file named "features/step_definitions/my_steps.js" with:
      """
      import assert from 'assert'
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({Given}) => {
        Given('a {param} step', function(param) {
          assert.equal(param, 'DEMO')
        })
      })
      """
    Given a file named "features/support/transforms.js" with:
      """
      import {defineSupportCode} from 'cucumber'

      defineSupportCode(({defineParameterType}) => {
        defineParameterType({
          regexp: /demo(?:nstration)?/,
          transformer: s => s.toUpperCase(),
          typeName: 'param'
        })
      })
      """
    When I run cucumber.js
    Then the step "a demo step" has status "passed"

Copied from original issue: cucumber/cucumber-js#849

@aslakhellesoy
Copy link
Contributor Author

Dupe of #211

@lock
Copy link

lock bot commented Oct 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

1 participant