Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion cucumber-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
13 changes: 11 additions & 2 deletions lib/cucumber/core/gherkin/parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'gherkin/gherkin'
require 'gherkin'

module Cucumber
module Core
Expand All @@ -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)
Expand All @@ -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
Expand Down
32 changes: 30 additions & 2 deletions lib/cucumber/core/gherkin/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions spec/cucumber/core/gherkin/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down