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

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

Open
ernstki opened this issue Jul 20, 2023 · 1 comment
Labels
🐛 bug Defect / Bug

Comments

@ernstki
Copy link

ernstki commented Jul 20, 2023

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
@luke-hill
Copy link
Contributor

Yep, definite bug. Not sure exactly where the auto-gen is done, as I've not used that area ever. But easy to repro my end - I'll try reproduce this weekend and then we can go from there.

@luke-hill luke-hill added the 🐛 bug Defect / Bug label Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants