Skip to content

Step name incorrect when multiple backslashes in Examples block #1006

Closed
@paoloambrosio-skyuk

Description

@paoloambrosio-skyuk

Summary

Step name is incorrect when multiple backslashes are present in the Examples block.

Expected Behavior

The step name should be obtained by just filling the placeholders with the values in the Examples block

The only escaping should be that defined by the Gherkin grammar:

The \-character will be considered as an escape in table cell iff it is followed by a |-character, a \-character or an n.

I would expect this feature to pass:

Feature: Escaping

  Scenario Outline:
    * '<a>' should equal '|'
    * '<b>' should equal '\\\+'
    * '<c>' should equal '\\\\\\'

    Examples:
      | a  | b       | c            |
      | \| | \\\\\\+ | \\\\\\\\\\\\ |

If run with this step definition:

Given(/^'([^']*)' should equal '([^']*)'$/) do |x,y|
  x.should == y
end

The same feature passes if run with Cucumber-JVM and this step definition:

@Given("^'([^']*)' should equal '([^']*)'$")
public void checkEquality(String x, String y) {
    assertEquals(y, x);
}

Current Behavior

It fails on the second step with:

      expected: "\\\\\\+"
           got: "\\" (using ==) (RSpec::Expectations::ExpectationNotMetError)
      ./features/step_definitions/escaping.rb:6:in `/^'([^']*)' should equal '([^']*)'$/'
      features/escaping.feature:10:in `* '\' should equal '\\\+''
      features/escaping.feature:5:in `* '<b>' should equal '\\\+''

By printing the step name in an AfterStep hook, the above Scenario Outline gets expanded to:

Feature: Escaping

  Scenario Outline:
    * '|' should equal '|'
    * '\' should equal '\\\+'
    * '\\\' should equal '\\\\\\'

Possible Solution

Escaping seems to be correct in the Gherkin parser (at least 4.0.0). The same issue is present at least from version 1.3.20 to the latest 2.4.0, so it's probably not a parser problem. No idea where to look in Cucumber-Ruby.

Steps to Reproduce (for bugs)

  1. Create a feature file and a step definition file as described in the "Expected Behavior" section
  2. Run Cucumber-Ruby

Context & Motivation

Was writing scenarios to test regex escaping in the snippets generation of Cucumber-CPP, that still uses Cucumber-Ruby and Aruba for E2E testing.

Your Environment

  • Version used: 1.3.20 (gherkin 2.12.2), 2.0.0 (gherkin 2.12.2), 2.4.0 (gherkin 4.0.0)
  • Operating System and version: OSX 10.11.6, Ruby 2.3.0 with RVM

Metadata

Metadata

Assignees

No one assigned

    Labels

    ⌛ staleWill soon be closed by stalebot unless there is activity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions