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
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
source "https://rubygems.org"
gemspec

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'

gemspec
6 changes: 3 additions & 3 deletions cucumber-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Gem::Specification.new do |s|
'source_code_uri' => 'https://github.com/cucumber/cucumber-ruby-core',
}

s.add_dependency 'gherkin', '~> 6.0.17'
s.add_dependency 'cucumber-tag_expressions', '~> 1.1.1'
s.add_dependency 'backports', '>= 3.8.0'
s.add_dependency 'gherkin', '~> 7.0', '>= 7.0.3'
s.add_dependency 'cucumber-tag_expressions', '~> 2.0', '>= 2.0.2'
s.add_dependency 'backports', '~> 3.15', '>= 3.15.0'

s.add_development_dependency 'bundler', '>= 1.16.0'
s.add_development_dependency 'rake', '>= 0.9.2'
Expand Down
44 changes: 23 additions & 21 deletions lib/cucumber/core/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,36 @@ def done
private

def create_test_case(pickle)
uri = pickle[:uri]
test_steps = pickle[:steps].map { |step| create_test_step(step, uri) }
lines = pickle[:locations].map { |location| location[:line] }.sort.reverse
tags = pickle[:tags].map { |tag| Test::Tag.new(Test::Location.new(uri, tag[:location][:line]), tag[:name]) }
Test::Case.new(pickle[:name], test_steps, Test::Location.new(uri, lines), tags, pickle[:language])
uri = pickle.uri
test_steps = pickle.steps.map { |step| create_test_step(step, uri) }
lines = pickle.locations.map { |location| location.line }.sort.reverse
tags = pickle.tags.map { |tag| Test::Tag.new(Test::Location.new(uri, tag.location.line), tag.name) }
Test::Case.new(pickle.name, test_steps, Test::Location.new(uri, lines), tags, pickle.language)
end

def create_test_step(pickle_step, uri)
lines = pickle_step[:locations].map { |location| location[:line] }.sort.reverse
lines = pickle_step.locations.map { |location| location.line }.sort.reverse
multiline_arg = create_multiline_arg(pickle_step, uri)
Test::Step.new(pickle_step[:text], Test::Location.new(uri, lines), multiline_arg)
Test::Step.new(pickle_step.text, Test::Location.new(uri, lines), multiline_arg)
end

def create_multiline_arg(pickle_step, uri)
if !pickle_step[:doc_string].nil?
argument = pickle_step[:doc_string]
Test::DocString.new(
argument[:content],
argument[:content_type],
Test::Location.new(uri, argument[:location][:line])
)
elsif !pickle_step[:data_table].nil?
argument = pickle_step[:data_table]
first_cell = argument[:rows].first[:cells].first
Test::DataTable.new(
argument[:rows].map { |row| row[:cells].map { |cell| cell[:value] } },
Test::Location.new(uri, first_cell[:location][:line])
)
if pickle_step.argument
if pickle_step.argument.doc_string
doc_string = pickle_step.argument.doc_string
Test::DocString.new(
doc_string.content,
doc_string.contentType,
Test::Location.new(uri, doc_string.location.line)
)
elsif pickle_step.argument.data_table
data_table = pickle_step.argument.data_table
first_cell = data_table.rows.first.cells.first
Test::DataTable.new(
data_table.rows.map { |row| row.cells.map { |cell| cell.value } },
Test::Location.new(uri, first_cell.location.line)
)
end
else
Test::EmptyMultilineArgument.new
end
Expand Down
9 changes: 4 additions & 5 deletions lib/cucumber/core/gherkin/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ def document(document)
messages = ::Gherkin::Gherkin.from_source(document.uri, document.body, {default_dialect: document.language, include_source: false})
messages.each do |message|
if !message.gherkinDocument.nil?
event_bus.gherkin_source_parsed(message.gherkinDocument.to_hash)
event_bus.gherkin_source_parsed(message.gherkinDocument)
elsif !message.pickle.nil?
receiver.pickle(message.pickle.to_hash)
receiver.pickle(message.pickle)
elsif !message.attachment.nil?
raise message.attachment.data
# Parse error
raise Core::Gherkin::ParseError.new("#{document.uri}: #{message.attachment.data}")
else
raise "Unknown message: #{message.to_hash}"
end
end
rescue RuntimeError => e
raise Core::Gherkin::ParseError.new("#{document.uri}: #{e.message}")
end

def done
Expand Down
24 changes: 24 additions & 0 deletions scripts/update-gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# Updates the *.gemspec in the current directory to use the latest releases of gems
#
set -uf -o pipefail
IFS=$'\n'

gemspec=$(find . -type f -maxdepth 1 -name "*.gemspec")
add_dependency_lines=$(cat ${gemspec} | grep "s.add_dependency '[^']*', '")
if [ $? -ne 0 ]; then
# No add_dependency_lines found - nothing to do
exit 0
fi

set -e

gems=$(echo "${add_dependency_lines}" | tr -s ' ' | cut -d ' ' -f3 | cut -d"'" -f 2)
while read -r gem; do
gem_line=$(gem list "${gem}" --remote --all --no-prerelease | grep "^${gem}\s")
latest_patch_version=$(echo "${gem_line}" | cut -d'(' -f2 | cut -d',' -f1)
latest_minor_version=$(echo "${latest_patch_version}" | cut -d. -f1,2)
cat "${gemspec}" | sed "s/s.add_dependency '${gem}', .*/s.add_dependency '${gem}', '~> ${latest_minor_version}', '>= ${latest_patch_version}'/" > ${gemspec}.tmp
mv ${gemspec}.tmp ${gemspec}
done <<< "${gems}"
2 changes: 1 addition & 1 deletion spec/cucumber/core/gherkin/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def self.source(&block)
end

RSpec::Matchers.define :pickle_with_language do |language|
match { |actual| actual[:language] == language }
match { |actual| actual.language == language }
end

context "when the Gherkin has a language header" do
Expand Down