Repository: cucumber/common

Issue #481: cucumber-expressions: Cucumber treats a (?!text) group as a capturing group; IndexError is then thrown
Created: 2018-09-20T18:19:28Z
Summary
Given a step definition with a regexp that contains a negative look ahead and a capturing group back to back, causes cucumber to fail to load and gives an unhelpful error message "index 2 out of matches (IndexError)". This is the step definition:
And(/^the Projected Answer Time shown in the response accounts for the timezone (?!offset)(.*)$/) do |timezone|
....
end

Expected Behavior



This step definition worked with v2.4.0, it should still work or provide a more detailed error message that would help resolve the problem.
Current Behavior



An index 2 out of matches (IndexError) error is raised:
index 2 out of matches (IndexError)
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/group_builder.rb:20:in `offset'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/group_builder.rb:20:in `build'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/group_builder.rb:19:in `block in build'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/group_builder.rb:19:in `map'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/group_builder.rb:19:in `build'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/tree_regexp.rb:51:in `match'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/argument.rb:10:in `build'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-expressions-5.0.17/lib/cucumber/cucumber_expressions/regular_expression.rb:32:in `match'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/glue/step_definition.rb:101:in `arguments_from'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/glue/registry_and_more.rb:66:in `block in step_matches'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/glue/registry_and_more.rb:65:in `each'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/glue/registry_and_more.rb:65:in `reduce'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/glue/registry_and_more.rb:65:in `step_matches'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/step_match_search.rb:19:in `call'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/step_match_search.rb:19:in `call'
/Users/madkins/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/delegate.rb:83:in `method_missing'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/step_match_search.rb:62:in `call'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:66:in `matches'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:47:in `result'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:37:in `find_match'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:33:in `attempt_to_activate'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:29:in `map'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:29:in `new_test_steps'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:23:in `test_case'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/filters/activate_steps.rb:12:in `test_case'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/test/case.rb:25:in `describe_to'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/test/filters/locations_filter.rb:18:in `block in done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/test/filters/locations_filter.rb:17:in `each'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/test/filters/locations_filter.rb:17:in `done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/filter.rb:62:in `done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/test/filters/tag_filter.rb:18:in `done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/compiler.rb:24:in `done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core/gherkin/parser.rb:37:in `done'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core.rb:32:in `parse'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-core-3.1.0/lib/cucumber/core.rb:21:in `compile'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/runtime.rb:74:in `run!'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/lib/cucumber/cli/main.rb:33:in `execute!'
/Users/madkins/.rvm/gems/ruby-2.4.2/gems/cucumber-3.1.0/bin/cucumber:9:in `<top (required)>'
/Users/madkins/.rvm/gems/ruby-2.4.2/bin/cucumber:23:in `load'
/Users/madkins/.rvm/gems/ruby-2.4.2/bin/cucumber:23:in `<main>'

Steps to Reproduce (for bugs)



Define the error raising step:

And(/^foo is a (?!big)(.*)$/) do |bar|
  puts bar
end

Define an ambiguous step to show the need for this to work:

And(/^foo is a big (.*)$/) do |bar|
  puts bar
end

Define 2 scenarios that utilize the steps:

  Scenario: Cucumber fails to load
    Given foo is a bar
    
  Scenario: Used to prevent ambiguous steps
    Given foo is a big bar

Run the tests: bundle exec cucumber

Your Environment


Version used: 3.10
Operating System and version: MacOS High Sierra 10.13.3

Related Issue: #329

Duplicate issue #510: Negative lookahead caused java.util.NoSuchElementException
Created: 2018-10-23T16:04:04Z
On cucumber-java 3.0.2, I use cucumber expression:
 ("^(.+): In (.+) I type ((?!value of).+)")
and this negative lookahead causes java.util.NoSuchElementException.

Closing comment (2019-03-04T19:19:32Z): I suspect this is related to #481