cucumber / cucumber/cucumber-ruby

Scenario having nested quotes produces syntactically-invalid step definition

Open
#1,710 2 comments 0 reactions 0 assignees View on GitHub
:bug: bug
Dominant language
Ruby
Stars
5.2k
Forks
1.1k
Avg merge
1d 16h
Merged PRs (30d)
3

Description

### What did you see?

Step definition produced by running `bundle exec cucumber` on [the following scenario](https://school.cucumber.io/courses/take/bdd-with-cucumber-ruby/lessons/11303805-add-a-scenario-wire-it-up) produces a syntax error when the code snippets are implemented as a step definition.

```cucumber
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:

```ruby
# ⋮
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?

``` ruby
# ⋮
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
```cucumber
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
```
8. Run command `bundle exec cucumber`
9. Copy-paste the snippet for the step definition into the file `features/step_definitions/steps.rb`
```ruby
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
```

11. Run `bundle exec cucumber` again
12. 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 `'
/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 `'
```

### See also

1. #1291
2. #1298
3.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.