Skip to content

Commit

Permalink
Use single updates in generated template steps
Browse files Browse the repository at this point in the history
When pending steps are generated for undefined steps, the step name does
not include any interpolation so double-quotes are not necessary. Only
the single-quotes are necessary for those strings.

This will make the generated steps allow consistent with the ruby style
guide:
  https://github.com/rubocop-hq/ruby-style-guide#strings

And with the default settings for Rubocop Style/StringLiterals cop:
  https://github.com/rubocop-hq/rubocop/blob/ab6346ed37d88a4b900c96979f8ef18959e8dcce/lib/rubocop/cop/style/string_literals.rb
  • Loading branch information
acant committed Oct 28, 2018
1 parent 9b910c9 commit 246504c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions features/docs/defining_steps/snippets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ Feature: Snippets
When I run `cucumber features/undefined_steps.feature -s`
Then the output should contain:
"""
Given("a Doc String") do |string|
Given('a Doc String') do |string|
pending # Write code here that turns the phrase above into concrete actions
end
When("{int} simple when step") do |int|
When('{int} simple when step') do |int|
pending # Write code here that turns the phrase above into concrete actions
end
When("another {string} step") do |string|
When('another {string} step') do |string|
pending # Write code here that turns the phrase above into concrete actions
end
Then("a simple then step") do
Then('a simple then step') do
pending # Write code here that turns the phrase above into concrete actions
end
"""
Expand All @@ -49,7 +49,7 @@ Feature: Snippets
When I run `cucumber features/undefined_steps.feature -s`
Then the output should contain:
"""
Given("a table") do |table|
Given('a table') do |table|
# table is a Cucumber::MultilineArgument::DataTable
pending # Write code here that turns the phrase above into concrete actions
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/glue/snippet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def typed_pattern
def to_s
header = generated_expressions.each_with_index.map do |expr, i|
prefix = i.zero? ? '' : '# '
"#{prefix}#{code_keyword}(\"#{expr.source}\") do#{parameters(expr)}"
"#{prefix}#{code_keyword}('#{expr.source}') do#{parameters(expr)}"
end.join("\n")

body = String.new # rubocop:disable Style/EmptyLiteral
Expand Down
28 changes: 14 additions & 14 deletions spec/cucumber/formatter/pretty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,12 @@ module Formatter
FEATURE

it "containes snippets with 'And' or 'But' replaced by previous step name" do
expect(@out.string).to include('Given("there are bananas and apples")')
expect(@out.string).to include('Given("other monkeys are around")')
expect(@out.string).to include('When("one monkey eats a banana")')
expect(@out.string).to include('When("the other monkeys eat all the apples")')
expect(@out.string).to include('Then("bananas remain")')
expect(@out.string).to include('Then("there are no apples left")')
expect(@out.string).to include("Given('there are bananas and apples')")
expect(@out.string).to include("Given('other monkeys are around')")
expect(@out.string).to include("When('one monkey eats a banana')")
expect(@out.string).to include("When('the other monkeys eat all the apples')")
expect(@out.string).to include("Then('bananas remain')")
expect(@out.string).to include("Then('there are no apples left')")
end
end

Expand All @@ -882,12 +882,12 @@ module Formatter
* there are no apples left
FEATURE
it "replaces the first step with 'Given'" do
expect(@out.string).to include('Given("there are bananas and apples")')
expect(@out.string).to include("Given('there are bananas and apples')")
end
it "uses actual keywords as the 'previous' keyword for future replacements" do
expect(@out.string).to include('Given("other monkeys are around")')
expect(@out.string).to include('When("the other monkeys eat all the apples")')
expect(@out.string).to include('Then("there are no apples left")')
expect(@out.string).to include("Given('other monkeys are around')")
expect(@out.string).to include("When('the other monkeys eat all the apples')")
expect(@out.string).to include("Then('there are no apples left')")
end
end

Expand All @@ -904,7 +904,7 @@ module Formatter
Given('this step passes') {}
end
it 'uses actual keyword of the previous passing step for the undefined step' do
expect(@out.string).to include('Then("this step is undefined")')
expect(@out.string).to include("Then('this step is undefined')")
end
end

Expand All @@ -924,8 +924,8 @@ module Formatter
Given('this step passes') {}
end
it "uses 'Given' as actual keyword the step in each scenario" do
expect(@out.string).to include('Given("this step is undefined")')
expect(@out.string).to include('Given("this step is also undefined")')
expect(@out.string).to include("Given('this step is undefined')")
expect(@out.string).to include("Given('this step is also undefined')")
end
end

Expand All @@ -939,7 +939,7 @@ module Formatter
AN I EAT CUCUMBRZ
FEATURE
it 'uses actual keyword of the previous passing step for the undefined step' do
expect(@out.string).to include('ICANHAZ("I EAT CUCUMBRZ")')
expect(@out.string).to include("ICANHAZ('I EAT CUCUMBRZ')")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/glue/snippet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def unindented(snippet)
))

expect(snippet.to_s).to eq unindented(%{
Given("I have {float} {cucumis} in my belly") do |float, cucumis|
# Given("I have {float} {veg} in my belly") do |float, veg|
Given('I have {float} {cucumis} in my belly') do |float, cucumis|
# Given('I have {float} {veg} in my belly') do |float, veg|
pending # Write code here that turns the phrase above into concrete actions
end
})
Expand Down

0 comments on commit 246504c

Please sign in to comment.