Skip to content

Scenario having nested quotes produces syntactically-invalid step definition #1710

Open
@ernstki

Description

@ernstki

What did you see?

Step definition produced by running bundle exec cucumber on the following scenario produces a syntax error when the code snippets are implemented as a step definition.

Scenario: Listener is within range
  Given Lucy is located 15 metres from Sean
  When Sean shouts "free bagels at Sean's"
  Then Lucy hears Sean's message

Produces:

# ⋮ 
Then('Lucy hears Sean's message') do
  pending # Write code here that turns the phrase above into concrete actions
end

…which results in a syntax error due to the unmatched single quote.

What did you expect to see?

# ⋮
Then("Lucy hears Sean's message") do
  pending # Write code here that turns the phrase above into concrete actions
end

…or something similar.

Which tool/library version are you using?

Cucumber v8.0.0.

How could we reproduce it?

Steps to reproduce the behavior:

  1. Install Ruby (I used v2.7.8 from MacPorts) and bundler (I used v2.1.4 from MacPorts)

  2. Create a directory for the example project and cd into it: mkdir shouty && cd shouty

  3. Run bundle config set path vendor/bundle

  4. Run bundle install

  5. Run bundle exec cucumber --init

  6. Create the file features/shout.feature with the following contents

    Scenario: Listener is within range
      Given Lucy is located 15 metres from Sean
      When Sean shouts "free bagels at Sean's"
      Then Lucy hears Sean's message
  7. Run command bundle exec cucumber

  8. Copy-paste the snippet for the step definition into the file features/step_definitions/steps.rb

    Given('Lucy is located {int} metres from Sean') do |int|
    # Given('Lucy is located {float} metres from Sean') do |float|
      pending # Write code here that turns the phrase above into concrete actions
    end
    
    When('Sean shouts {string}') do |string|
      pending # Write code here that turns the phrase above into concrete actions
    end
    
    Then('Lucy hears Sean's message') do
      pending # Write code here that turns the phrase above into concrete actions
    end
  9. Run bundle exec cucumber again

  10. See the error message:

    /path/to/shouty/features/step_definitions/steps.rb10: syntax error, unexpected local variable or method, expecting ')'
    Then('Lucy hears Sean's message') do
                        ^
    /path/to/shouty/features/step_definitions/steps.rb12: unterminated string meets end of file (SyntaxError)
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/glue/registry_and_more.rb123:in `require'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/glue/registry_and_more.rb123:in `load_code_file'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb145:in `load_file'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb82:in `block in load_files!'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb81:in `each'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime/support_code.rb81:in `load_files!'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime.rb274:in `load_step_definitions'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/runtime.rb74:in `run!'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/lib/cucumber/cli/main.rb29:in `execute!'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/gems/cucumber-8.0.0/bin/cucumber9:in `<top (required)>'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/bin/cucumber23:in `load'
    /path/to/shouty/vendor/bundle/ruby/2.7.0/bin/cucumber23:in `<main>'
    

See also

  1. Wrong step definition created when having "(" #1291
  2. Use single quotes for snippets #1298
  3. https://school.cucumber.io/courses/take/bdd-with-cucumber-ruby/lessons/11303805-add-a-scenario-wire-it-up

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions