-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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 👍 |
The documentation PR has been merged, so we should probably merge this one, too, for consistency. :) |
There was a problem hiding this 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)}" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😂
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
@aslakhellesoy It looks to me like implementing the escape will involve changes to Cucumber Expressions since |
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. |
Bump :-) |
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. |
Bump. This is still on my radar, I'm just moving to Australia next Sunday so things have been hectic. |
Take your time @danascheider - good luck with the move. We'll keep this one waiting for you down under. |
@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. |
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. |
This PR addresses #1291 by changing snippets to use single quotes rather than double quotes.
Details
Previously, snippets looked like this:
Now, this snippet would look like this:
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
Checklist: