From c090a71a1f7c4a0694c68c781cc9dea29fe53b57 Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 22 Nov 2023 17:09:52 +0000 Subject: [PATCH 1/6] Initial work to remove unindent and use squiggly heredocs --- spec/cucumber/core/gherkin/writer_spec.rb | 242 ++++++++++++---------- 1 file changed, 138 insertions(+), 104 deletions(-) diff --git a/spec/cucumber/core/gherkin/writer_spec.rb b/spec/cucumber/core/gherkin/writer_spec.rb index 5578d11c..0db95811 100644 --- a/spec/cucumber/core/gherkin/writer_spec.rb +++ b/spec/cucumber/core/gherkin/writer_spec.rb @@ -1,23 +1,25 @@ # frozen_string_literal: true require 'cucumber/core/gherkin/writer' -require 'unindent' describe Cucumber::Core::Gherkin::Writer do include described_class it 'generates a uri by default' do source = gherkin { feature } + expect(source.uri).to eq 'features/test.feature' end it 'allows you to specify a URI' do source = gherkin('features/path/to/my.feature') { feature } + expect(source.uri).to eq 'features/path/to/my.feature' end it 'generates the feature statement by default' do source = gherkin { feature } + expect(source).to eq "Feature:\n" end @@ -26,27 +28,31 @@ source = gherkin do feature "A Feature\n" end + expect(source).to eq "Feature: A Feature\n" end end context 'when a description is provided' do + let(:expected) do + <<~FEATURE + Feature: A Feature + This is the description + which can span + multiple lines. + FEATURE + end + it 'includes the description in the feature statement' do source = gherkin do - feature 'A Feature', description: <<-FEATURE - This is the description - which can span - multiple lines. + feature 'A Feature', description: <<~FEATURE + This is the description + which can span + multiple lines. FEATURE end - expected = <<-FEATURE - Feature: A Feature - This is the description - which can span - multiple lines. - FEATURE - expect(source).to eq expected.unindent + expect(source).to eq(expected) end end @@ -55,7 +61,8 @@ source = gherkin do feature 'A Feature', keyword: 'Business Need' end - expect(source).to eq "Business Need: A Feature\n" + + expect(source).to eq("Business Need: A Feature\n") end end @@ -65,7 +72,7 @@ feature language: 'ru' end - expect(source).to eq "# language: ru\nFeature:\n" + expect(source).to eq("# language: ru\nFeature:\n") end end @@ -93,6 +100,15 @@ end context 'when a comment is provided' do + let(:expected) do + <<~FEATURE + Feature: + + # wow + Scenario: + FEATURE + end + it 'includes the comment in the scenario statement' do source = gherkin do feature do @@ -100,35 +116,35 @@ scenario end end - expect(source.to_s).to eq <<-FEATURE.unindent - Feature: - # wow - Scenario: - FEATURE + expect(source.to_s).to eq(expected) end end context 'when a description is provided' do + let(:expected) do + <<~FEATURE + Feature: + + Scenario: + This is the description + which can span + multiple lines. + FEATURE + end + it 'includes the description in the scenario statement' do source = gherkin do feature do - scenario description: <<-SCENARIO - This is the description - which can span - multiple lines. + scenario description: <<~SCENARIO + This is the description + which can span + multiple lines. SCENARIO end end - expect(source).to eq <<-FEATURE.unindent - Feature: - - Scenario: - This is the description - which can span - multiple lines. - FEATURE + expect(source).to eq(expected) end end @@ -146,6 +162,18 @@ end context 'when a docstring is provided' do + let(:expected) do + <<~FEATURE + Feature: + + Scenario: + Given failing + """text/plain + some text + """ + FEATURE + end + it 'includes the content type when provided' do source = gherkin do feature do @@ -157,21 +185,23 @@ end end - expect(source).to eq <<-FEATURE.unindent - Feature: - - Scenario: - Given failing - """text/plain - some text - """ - FEATURE + expect(source).to eq(expected) end end end end context 'with a background' do + let(:expected) do + <<~FEATURE + Feature: + + Background: + One line, + and two.. + FEATURE + end + it 'can have a description' do source = gherkin do feature do @@ -179,17 +209,20 @@ end end - expect(source).to eq <<-FEATURE.unindent - Feature: - - Background: - One line, - and two.. - FEATURE + expect(source).to eq(expected) end end context 'with a scenario outline' do + let(:expected) do + <<~FEATURE + Feature: + + Scenario Outline: + Doesn't need to be multi-line. + FEATURE + end + it 'can have a description' do source = gherkin do feature do @@ -197,15 +230,21 @@ end end - expect(source).to eq <<-FEATURE.unindent - Feature: - - Scenario Outline: - Doesn't need to be multi-line. - FEATURE + expect(source).to eq(expected) end context 'with an examples table' do + let(:expected) do + <<~FEATURE + Feature: + + Scenario Outline: + + Examples: + Doesn't need to be multi-line. + FEATURE + end + it 'can have a description' do source = gherkin do feature do @@ -215,14 +254,7 @@ end end - expect(source).to eq <<-FEATURE.unindent - Feature: - - Scenario Outline: - - Examples: - Doesn't need to be multi-line. - FEATURE + expect(source).to eq(expected) end end end @@ -245,9 +277,9 @@ comment 'and here' step 'passing' step 'failing', keyword: 'When' do - doc_string <<-DOC_STRING - I wish I was a little bit taller. - I wish I was a baller. + doc_string <<~DOC_STRING + I wish I was a little bit taller. + I wish I was a baller. DOC_STRING end end @@ -277,46 +309,48 @@ end end - expect(source.to_s).to eq <<-FEATURE.unindent -# language: en -# wow -@always -Feature: Fully featured - - # cool - Background: - Given passing - - Scenario: - Given passing - - # here - @first @second - Scenario: with doc string - # and here - Given passing - When failing - """ - I wish I was a little bit taller. - I wish I was a baller. - """ - - Scenario: with a table... - Given passes: - | name | age | location | - | Janine | 43 | Antarctica | - - # yay - Scenario Outline: eating - Given there are cucumbers - When I eat cucumbers - Then I should have cucumbers - - # hmmm - Examples: - | start | eat | left | - | 12 | 5 | 7 | - | 20 | 5 | 15 | + expected = <<~FEATURE + # language: en + # wow + @always + Feature: Fully featured + + # cool + Background: + Given passing + + Scenario: + Given passing + + # here + @first @second + Scenario: with doc string + # and here + Given passing + When failing + """ + I wish I was a little bit taller. + I wish I was a baller. + """ + + Scenario: with a table... + Given passes: + | name | age | location | + | Janine | 43 | Antarctica | + + # yay + Scenario Outline: eating + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + # hmmm + Examples: + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 15 | FEATURE + + expect(source.to_s).to eq(expected) end end From 556ac749f5adbf119e3975c50f480783bcd2e88e Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 22 Nov 2023 17:10:01 +0000 Subject: [PATCH 2/6] Remove gem --- cucumber-core.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/cucumber-core.gemspec b/cucumber-core.gemspec index 117a96bf..d8cebaa2 100644 --- a/cucumber-core.gemspec +++ b/cucumber-core.gemspec @@ -33,7 +33,6 @@ Gem::Specification.new do |s| s.add_development_dependency 'rubocop-rake', '~> 0.6.0' s.add_development_dependency 'rubocop-rspec', '2.8' s.add_development_dependency 'rubocop-packaging', '~> 0.5', '>= 0.5.1' - s.add_development_dependency 'unindent', '~> 1.0', '>= 1.0' s.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'README.md', 'LICENSE', 'lib/**/*'] s.rdoc_options = ['--charset=UTF-8'] From 608ecf3da3f528812065f930ea2845ab1ff48351 Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 22 Nov 2023 17:10:23 +0000 Subject: [PATCH 3/6] Fix whitespace issues --- spec/cucumber/core/gherkin/writer_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/cucumber/core/gherkin/writer_spec.rb b/spec/cucumber/core/gherkin/writer_spec.rb index 0db95811..1693659c 100644 --- a/spec/cucumber/core/gherkin/writer_spec.rb +++ b/spec/cucumber/core/gherkin/writer_spec.rb @@ -103,7 +103,7 @@ let(:expected) do <<~FEATURE Feature: - + # wow Scenario: FEATURE @@ -195,7 +195,7 @@ let(:expected) do <<~FEATURE Feature: - + Background: One line, and two.. @@ -217,7 +217,7 @@ let(:expected) do <<~FEATURE Feature: - + Scenario Outline: Doesn't need to be multi-line. FEATURE @@ -237,9 +237,9 @@ let(:expected) do <<~FEATURE Feature: - + Scenario Outline: - + Examples: Doesn't need to be multi-line. FEATURE @@ -314,14 +314,14 @@ # wow @always Feature: Fully featured - + # cool Background: Given passing - + Scenario: Given passing - + # here @first @second Scenario: with doc string @@ -332,18 +332,18 @@ I wish I was a little bit taller. I wish I was a baller. """ - + Scenario: with a table... Given passes: | name | age | location | | Janine | 43 | Antarctica | - + # yay Scenario Outline: eating Given there are cucumbers When I eat cucumbers Then I should have cucumbers - + # hmmm Examples: | start | eat | left | From 05476111ba2613abc4256bb914aabdd923255aa0 Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 22 Nov 2023 17:12:09 +0000 Subject: [PATCH 4/6] Fix up linting of assertions --- spec/cucumber/core/gherkin/writer_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/cucumber/core/gherkin/writer_spec.rb b/spec/cucumber/core/gherkin/writer_spec.rb index 1693659c..046de1c7 100644 --- a/spec/cucumber/core/gherkin/writer_spec.rb +++ b/spec/cucumber/core/gherkin/writer_spec.rb @@ -8,19 +8,19 @@ it 'generates a uri by default' do source = gherkin { feature } - expect(source.uri).to eq 'features/test.feature' + expect(source.uri).to eq('features/test.feature') end it 'allows you to specify a URI' do source = gherkin('features/path/to/my.feature') { feature } - expect(source.uri).to eq 'features/path/to/my.feature' + expect(source.uri).to eq('features/path/to/my.feature') end it 'generates the feature statement by default' do source = gherkin { feature } - expect(source).to eq "Feature:\n" + expect(source).to eq("Feature:\n") end context 'when a name is provided' do @@ -29,7 +29,7 @@ feature "A Feature\n" end - expect(source).to eq "Feature: A Feature\n" + expect(source).to eq("Feature: A Feature\n") end end @@ -84,7 +84,7 @@ feature end - expect(source.to_s).to eq "# wow\n# great\nFeature:\n" + expect(source.to_s).to eq("# wow\n# great\nFeature:\n") end end From 4c9dc463537cad3887abeaf9d66c600b31711e69 Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 29 Nov 2023 11:25:54 +0000 Subject: [PATCH 5/6] Update rubocop todo file and slight update to rubocop gems --- .rubocop_todo.yml | 24 ++-- cucumber-core.gemspec | 6 +- spec/cucumber/core/gherkin/writer_spec.rb | 148 ++++++++++------------ 3 files changed, 84 insertions(+), 94 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 153b6c40..ddc4d8eb 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-11-16 16:44:59 UTC using RuboCop version 1.27.0. +# on 2023-11-29 11:28:59 UTC using RuboCop version 1.28.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,7 +9,8 @@ # TODO: [LH] Initial state -> 53 files inspected, 2221 offenses detected, 1663 offenses auto-correctable # TODO: [LH] Part 1 iteration -> 53 files inspected, 1990 offenses detected, 1442 offenses auto-correctable # TODO: [LH] Part 2 iteration -> 53 files inspected, 506 offenses detected, 163 offenses auto-correctable -# TODO: [LH] v13 -> 53 files inspected, 450 offenses detected, 150 offenses auto-correctable +# TODO: [LH] v12 -> 53 files inspected, 450 offenses detected, 150 offenses auto-correctable +# TODO: [LH] v12 -> 53 files inspected, 453 offenses detected, 148 offenses auto-correctable # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). @@ -55,11 +56,10 @@ Layout/FirstArrayElementIndentation: Exclude: - 'spec/cucumber/core_spec.rb' -# Offense count: 2 +# Offense count: 1 # This cop supports safe auto-correction (--auto-correct). Layout/HeredocIndentation: Exclude: - - 'spec/cucumber/core/gherkin/writer_spec.rb' - 'spec/cucumber/core/test/doc_string_spec.rb' # Offense count: 2 @@ -116,7 +116,7 @@ Layout/TrailingWhitespace: Metrics/AbcSize: Max: 23 -# Offense count: 54 +# Offense count: 55 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: @@ -145,7 +145,13 @@ Naming/RescuedExceptionsVariableName: - 'lib/cucumber/core/test/action.rb' - 'lib/cucumber/core/test/around_hook.rb' -# Offense count: 64 +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +RSpec/BeEq: + Exclude: + - 'spec/cucumber/core/event_bus_spec.rb' + +# Offense count: 63 # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnabledMethods. RSpec/Capybara/FeatureMethods: @@ -173,10 +179,10 @@ RSpec/DescribedClass: Exclude: - 'spec/cucumber/core/test/doc_string_spec.rb' -# Offense count: 44 +# Offense count: 50 # Configuration parameters: CountAsOne. RSpec/ExampleLength: - Max: 20 + Max: 32 # Offense count: 1 # This cop supports safe auto-correction (--auto-correct). @@ -403,7 +409,7 @@ Style/SymbolArray: # Offense count: 2 # This cop supports unsafe auto-correction (--auto-correct-all). -# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods. +# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods, AllowComments. # IgnoredMethods: respond_to, define_method Style/SymbolProc: Exclude: diff --git a/cucumber-core.gemspec b/cucumber-core.gemspec index d8cebaa2..11fdfd18 100644 --- a/cucumber-core.gemspec +++ b/cucumber-core.gemspec @@ -29,10 +29,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6' s.add_development_dependency 'rspec', '~> 3.11', '>= 3.11.0' - s.add_development_dependency 'rubocop', '1.27' + s.add_development_dependency 'rubocop', '~> 1.28.2' s.add_development_dependency 'rubocop-rake', '~> 0.6.0' - s.add_development_dependency 'rubocop-rspec', '2.8' - s.add_development_dependency 'rubocop-packaging', '~> 0.5', '>= 0.5.1' + s.add_development_dependency 'rubocop-rspec', '~> 2.10.0' + s.add_development_dependency 'rubocop-packaging', '~> 0.5.1' s.files = Dir['CHANGELOG.md', 'CONTRIBUTING.md', 'README.md', 'LICENSE', 'lib/**/*'] s.rdoc_options = ['--charset=UTF-8'] diff --git a/spec/cucumber/core/gherkin/writer_spec.rb b/spec/cucumber/core/gherkin/writer_spec.rb index 046de1c7..f0e910d4 100644 --- a/spec/cucumber/core/gherkin/writer_spec.rb +++ b/spec/cucumber/core/gherkin/writer_spec.rb @@ -259,98 +259,82 @@ end end - it 'can generate a complex feature' do - source = gherkin do - comment 'wow' - feature 'Fully featured', language: 'en', tags: '@always' do - comment 'cool' - background do - step 'passing' - end + context 'with a feature file with many options' do + let(:expected) do + <<~FEATURE + # language: en + # wow + @always + Feature: Fully featured - scenario do - step 'passing' - end + # cool + Background: + Given passing + + Scenario: + Given passing + + # here + @first @second + Scenario: with doc string + # and here + Given failing + """ + I wish I was a little bit taller + """ + + # yay + Scenario Outline: eating + Given there are cucumbers + When I eat cucumbers + Then I should have cucumbers + + # hmmm + Examples: + | start | eat | left | + | 12 | 5 | 7 | + | 20 | 5 | 15 | + FEATURE + end + + it 'can generate a complex feature' do + source = gherkin do + comment 'wow' + feature 'Fully featured', language: 'en', tags: '@always' do + comment 'cool' + background do + step 'passing' + end - comment 'here' - scenario 'with doc string', tags: '@first @second' do - comment 'and here' - step 'passing' - step 'failing', keyword: 'When' do - doc_string <<~DOC_STRING - I wish I was a little bit taller. - I wish I was a baller. - DOC_STRING + scenario do + step 'passing' end - end - scenario 'with a table...' do - step 'passes:' do - table do - row 'name', 'age', 'location' - row 'Janine', '43', 'Antarctica' + comment 'here' + scenario 'with doc string', tags: '@first @second' do + comment 'and here' + step 'failing' do + doc_string 'I wish I was a little bit taller' end end - end - comment 'yay' - scenario_outline 'eating' do - step 'there are cucumbers' - step 'I eat cucumbers', keyword: 'When' - step 'I should have cucumbers', keyword: 'Then' - - comment 'hmmm' - examples do - row 'start', 'eat', 'left' - row '12', '5', '7' - row '20', '5', '15' + comment 'yay' + scenario_outline 'eating' do + step 'there are cucumbers' + step 'I eat cucumbers', keyword: 'When' + step 'I should have cucumbers', keyword: 'Then' + + comment 'hmmm' + examples do + row 'start', 'eat', 'left' + row '12', '5', '7' + row '20', '5', '15' + end end end end - end - expected = <<~FEATURE - # language: en - # wow - @always - Feature: Fully featured - - # cool - Background: - Given passing - - Scenario: - Given passing - - # here - @first @second - Scenario: with doc string - # and here - Given passing - When failing - """ - I wish I was a little bit taller. - I wish I was a baller. - """ - - Scenario: with a table... - Given passes: - | name | age | location | - | Janine | 43 | Antarctica | - - # yay - Scenario Outline: eating - Given there are cucumbers - When I eat cucumbers - Then I should have cucumbers - - # hmmm - Examples: - | start | eat | left | - | 12 | 5 | 7 | - | 20 | 5 | 15 | - FEATURE - - expect(source.to_s).to eq(expected) + expect(source.to_s).to eq(expected) + end end end From b2ea9d76ef05525a36b481cdc17a6dc9a45a6dfe Mon Sep 17 00:00:00 2001 From: Luke Hill Date: Wed, 29 Nov 2023 11:38:21 +0000 Subject: [PATCH 6/6] Add changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecaa0d5d..009d5cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,16 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo - Now using a 2-tiered changelog to avoid any bugs when using polyglot-release - More refactoring of the repo by fixing up a bunch of manual rubocop offenses (See PR's for details) ([#259](https://github.com/cucumber/cucumber-ruby-core/pull/259) [#262](https://github.com/cucumber/cucumber-ruby-core/pull/262) [#268](https://github.com/cucumber/cucumber-ruby-core/pull/268) [#274](https://github.com/cucumber/cucumber-ruby-core/pull/274)) -- In all `Summary` and `Result` classes, changed the `strict` argument into a keyword argument. +- In all `Summary` and `Result` classes, changed the `strict` argument into a keyword argument See upgrading notes for [13.0.0.md](upgrading_notes/13.0.0.md#upgrading-to-1300) ([#261](https://github.com/cucumber/cucumber-ruby-core/pull/261)) - Permit usage of gherkin v27 ### Fixed -- Restore support for matching a scenario by its Feature, Background, and Rule line numbers. ([#247](https://github.com/cucumber/cucumber-ruby-core/pull/237)) +- Restore support for matching a scenario by its Feature, Background, and Rule line numbers ([#247](https://github.com/cucumber/cucumber-ruby-core/pull/247)) + +### Removed +- Remove legacy `unindent` gem (Now no longer required since Ruby 2.3 and Squiggly heredocs) ([#278](https://github.com/cucumber/cucumber-ruby-core/pull/278)) ## [12.0.0] - 2023-09-06 ### Changed