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

Use single quotes for snippets #1298

Closed
wants to merge 3 commits into from

Conversation

danascheider
Copy link
Contributor

@danascheider danascheider commented May 26, 2018

This PR addresses #1291 by changing snippets to use single quotes rather than double quotes.

Details

Previously, snippets looked like this:

Given("a user named {string}") do
  ...
end

Now, this snippet would look like this:

Given('a user named {string}') do
  ...
end

Motivation and Context

This PR fixes #1291, in which parentheses and brackets are not escaped correctly using double quotes. Following @aslakhellesoy's suggestion, instead of adding an extra escape character, I simply changed the snippets to use single quotes instead of double

How Has This Been Tested?

All Cucumber features and RSpec examples have been updated to incorporate the single quotes. I also added a Cucumber scenario testing that the characters are escaped correctly.

Types of changes

  • Refactor (code change that does not change external functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I've added tests for my code
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@luke-hill
Copy link
Contributor

luke-hill commented May 29, 2018

Seems legit: Only thing I'd mention is this line (https://github.com/cucumber/cucumber-ruby/pull/1298/files#diff-2de4df90923d3667d3424beee025f01cR898) probably needs rewriting to specify in a bit more detail what the unit test does. But it's not a red/green line. So seems cool from me 👍

@xtrasimplicity
Copy link
Member

xtrasimplicity commented May 31, 2018

The documentation PR has been merged, so we should probably merge this one, too, for consistency. :)

Copy link
Contributor

@aslakhellesoy aslakhellesoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge, there aren't any widely accepted conventions for the use of single or double qutes.

With Cucumber I prefer to use double quotes, because I use single quotes in steps relatively often:

Given Aslak has joined Dana's game

With double quotes I don't have to escape them in the Cucumber Expression.

I mentioned in #1291 that using single quotes would be a workaround. I didn't mean that it would be a general solution to the problem.

I think a better fix would be to keep the double quotes, and escape any \ characters in the expression with \\.

@@ -88,7 +88,7 @@ def typed_pattern
def to_s
header = generated_expressions.each_with_index.map do |expr, i|
prefix = i == 0 ? '' : '# '
"#{prefix}#{code_keyword}(\"#{expr.source}\") do#{parameters(expr)}"
"#{prefix}#{code_keyword}('#{expr.source}') do#{parameters(expr)}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered the case where expr.source contains a single quote?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, if we keep the double-quoted strings, the case where expr.source contains a \ character.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh! Good point. I actually agree with everything you’re saying and would also prefer the double quotes to stay. I just misread your other comments and took them to mean you preferred this way, and deferred to that even though I didn’t agree 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m making myself a note to submit new documentation changes tomorrow morning and change this PR right away.

pending # Write code here that turns the phrase above into concrete actions
end

Given('another step with \{brackets}') do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's called curly braces, or just braces

@danascheider
Copy link
Contributor Author

@aslakhellesoy It looks to me like implementing the escape will involve changes to Cucumber Expressions since expr.source might contain params in curly braces. I might be able to find a workaround for this using expr.parameter_names but it might be easier to add the escape character in Cucumber expressions before the params are interpolated. WDYT?

@stale
Copy link

stale bot commented Jul 30, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Jul 30, 2018
@aslakhellesoy
Copy link
Contributor

Bump :-)

@stale stale bot removed the ⌛ stale Will soon be closed by stalebot unless there is activity label Jul 30, 2018
@stale
Copy link

stale bot commented Sep 28, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Sep 28, 2018
@aslakhellesoy aslakhellesoy removed the ⌛ stale Will soon be closed by stalebot unless there is activity label Sep 28, 2018
@danascheider
Copy link
Contributor Author

Bump. This is still on my radar, I'm just moving to Australia next Sunday so things have been hectic.

@aslakhellesoy
Copy link
Contributor

Take your time @danascheider - good luck with the move. We'll keep this one waiting for you down under.

@danascheider
Copy link
Contributor Author

@aslakhellesoy I'm closing this PR since we decided on a different implementation. I'll open a new one when I have that implementation fleshed out more fully.

@danascheider danascheider deleted the 1291-use-single-quotes-in-snippets branch October 24, 2018 22:44
@lock
Copy link

lock bot commented Oct 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong step definition created when having "("
4 participants