diff --git a/CHANGELOG.md b/CHANGELOG.md index b91bd831..7806429e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,29 +4,13 @@ Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CO ### Changed -* N/A - -### Added - -* N/A - -### Fixed - -* N/A - -### Removed - -* N/A - -### Improved - -* N/A +* Update to use Gherkin v8 ## [5.0.1](https://github.com/cucumber/cucumber-ruby-core/compare/v5.0.0...v5.0.1) ### Removed -* Remove support for ruby 2.2 and below. 2.3 or higher is required now. +* Remove support for ruby 2.2 and below. 2.3 or higher is required now. ## [5.0.0](https://github.com/cucumber/cucumber-ruby-core/compare/v4.0.0...v5.0.0) diff --git a/Gemfile b/Gemfile index 62630760..82e3e1b0 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gem 'gherkin', path: ENV['GHERKIN_RUBY'] if ENV['GHERKIN_RUBY'] gem 'cucumber-messages', path: ENV['CUCUMBER_MESSAGES_RUBY'] if ENV['CUCUMBER_MESSAGES_RUBY'] -# Use an older protobuf on JRuby and MRI < 2.5 -gem 'google-protobuf', '~> 3.2.0.2' if RbConfig::CONFIG['MAJOR'].to_i == 2 && RbConfig::CONFIG['MINOR'].to_i < 5 || RUBY_PLATFORM == 'java' +# Use an older protobuf on JRuby +gem 'google-protobuf', '~> 3.2.0.2' if RUBY_PLATFORM == 'java' gemspec diff --git a/cucumber-core.gemspec b/cucumber-core.gemspec index 88dc62ef..281bb3e1 100644 --- a/cucumber-core.gemspec +++ b/cucumber-core.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |s| 'source_code_uri' => 'https://github.com/cucumber/cucumber-ruby-core', } - s.add_dependency 'gherkin', '~> 7.0', '>= 7.0.3' + s.add_dependency 'gherkin', '~> 8.1', '>= 8.1.1' s.add_dependency 'cucumber-tag_expressions', '~> 2.0', '>= 2.0.2' s.add_dependency 'backports', '~> 3.15', '>= 3.15.0' diff --git a/lib/cucumber/core/gherkin/parser.rb b/lib/cucumber/core/gherkin/parser.rb index 54c0b046..2a5f0b91 100644 --- a/lib/cucumber/core/gherkin/parser.rb +++ b/lib/cucumber/core/gherkin/parser.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -require 'gherkin/gherkin' +require 'gherkin' module Cucumber module Core @@ -16,7 +16,7 @@ def initialize(receiver, event_bus) end def document(document) - messages = ::Gherkin::Gherkin.from_source(document.uri, document.body, {default_dialect: document.language, include_source: false}) + messages = ::Gherkin.from_source(document.uri, document.body, gherkin_options(document)) messages.each do |message| if !message.gherkinDocument.nil? event_bus.gherkin_source_parsed(message.gherkinDocument) @@ -31,6 +31,15 @@ def document(document) end end + def gherkin_options(document) + { + default_dialect: document.language, + include_source: false, + include_gherkin_document: true, + include_pickles: true + } + end + def done receiver.done self diff --git a/lib/cucumber/core/gherkin/writer.rb b/lib/cucumber/core/gherkin/writer.rb index c63bea3d..02564161 100644 --- a/lib/cucumber/core/gherkin/writer.rb +++ b/lib/cucumber/core/gherkin/writer.rb @@ -48,7 +48,7 @@ class Feature default_keyword 'Feature' - elements :background, :scenario, :scenario_outline + elements :background, :rule, :scenario, :scenario_outline def build(source = []) elements.inject(source + statements) { |acc, el| el.build(acc) + [NEW_LINE] } @@ -85,7 +85,29 @@ class Background private def statements - prepare_statements comments_statement, tag_statement, name_statement, description_statement + prepare_statements comments_statement, + tag_statement, + name_statement, + description_statement + end + end + + class Rule + include HasElements + include HasOptionsInitializer + include HasDescription + include Indentation.level 2 + + default_keyword 'Rule' + + elements :example, :scenario + + private + def statements + prepare_statements comments_statement, + name_statement, + description_statement, + NEW_LINE end end @@ -108,6 +130,12 @@ def statements end end + class Example < Scenario + include Indentation.level 4 + + default_keyword 'Example' + end + class ScenarioOutline include HasElements include HasOptionsInitializer diff --git a/spec/cucumber/core/gherkin/parser_spec.rb b/spec/cucumber/core/gherkin/parser_spec.rb index 078da887..f5b3ae7d 100644 --- a/spec/cucumber/core/gherkin/parser_spec.rb +++ b/spec/cucumber/core/gherkin/parser_spec.rb @@ -89,6 +89,57 @@ def self.source(&block) end end + context "when scenario is inside a rule" do + source do + feature do + rule do + scenario name: "My scenario" + end + end + end + + it "passes on the pickle" do + expect( receiver ).to receive(:pickle) + parse + end + end + + context "when example is inside a rule" do + source do + feature do + rule do + example name: "My example" + end + end + end + + it "passes on the pickle" do + expect( receiver ).to receive(:pickle) + parse + end + end + + context "when there are multiple rules and scenarios or examples" do + source do + feature do + rule description: "First rule" do + scenario name: "Do not talk about the fight club" do + step 'text' + end + end + rule description: "Second rule"do + example name: "Do not talk about the fight club" do + step 'text' + end + end + end + end + + it "passes on the pickles" do + expect( receiver ).to receive(:pickle).twice + parse + end + end end end end