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
4 changes: 4 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ Metrics/ModuleLength:
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 7
Exclude:
- 'lib/cucumber/core/test/case.rb'
Comment thread
luke-hill marked this conversation as resolved.

# Offense count: 4
# This cop supports safe auto-correction (--auto-correct).
Expand Down Expand Up @@ -227,6 +229,8 @@ RSpec/MultipleExpectations:
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 20
Exclude:
Comment thread
luke-hill marked this conversation as resolved.
- 'spec/cucumber/core/test/runner_spec.rb'

# Offense count: 13
RSpec/NestedGroups:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
([#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))

## [12.0.0] - 2023-09-06
### Changed
- Update gherkin and messages minimum dependencies
Expand Down
2 changes: 1 addition & 1 deletion cucumber-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Gem::Specification.new do |s|
'source_code_uri' => 'https://github.com/cucumber/cucumber-ruby-core'
}

s.add_dependency 'cucumber-gherkin', '>= 25', '< 28'
s.add_dependency 'cucumber-gherkin', '>= 27', '< 28'
s.add_dependency 'cucumber-messages', '>= 20', '< 23'
s.add_dependency 'cucumber-tag-expressions', '~> 5.0', '>= 5.0.4'

Expand Down
43 changes: 25 additions & 18 deletions lib/cucumber/core/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,66 +37,73 @@ def done
def create_test_case(pickle)
uri = pickle.uri
test_steps = pickle.steps.map { |step| create_test_step(step, uri) }
lines = source_lines_for_pickle(pickle).sort.reverse
tags = source_lines_for_all_pickle_tags(pickle, uri)
test_case = Test::Case.new(id_generator.new_id, pickle.name, test_steps, Test::Location.new(uri, lines), tags, pickle.language)
location = location_from_pickle(pickle)
parent_locations = parent_locations_from_pickle(pickle)
tags = tags_from_pickle(pickle, uri)
test_case = Test::Case.new(id_generator.new_id, pickle.name, test_steps, location, parent_locations, tags, pickle.language)
@event_bus&.test_case_created(test_case, pickle)
test_case
end

def create_test_step(pickle_step, uri)
lines = source_lines_for_pickle_step(pickle_step).sort.reverse
location = location_from_pickle_step(pickle_step, uri)
multiline_arg = create_multiline_arg(pickle_step, uri)
step = Test::Step.new(id_generator.new_id, pickle_step.text, Test::Location.new(uri, lines), multiline_arg)
step = Test::Step.new(id_generator.new_id, pickle_step.text, location, multiline_arg)
@event_bus&.test_step_created(step, pickle_step)
step
end

def create_multiline_arg(pickle_step, _uri)
if pickle_step.argument
if pickle_step.argument.doc_string
pickle_step_for_doc_string(pickle_step)
doc_string_from_pickle_step(pickle_step)
elsif pickle_step.argument.data_table
pickle_step_for_data_table(pickle_step)
data_table_from_pickle_step(pickle_step)
end
else
Test::EmptyMultilineArgument.new
end
end

def source_lines_for_pickle(pickle)
pickle.ast_node_ids.map { |id| source_line(id) }
def location_from_pickle(pickle)
lines = pickle.ast_node_ids.map { |id| source_line(id) }
Test::Location.new(pickle.uri, lines.sort.reverse)
end

def source_lines_for_pickle_step(pickle_step)
pickle_step.ast_node_ids.map { |id| source_line(id) }
def parent_locations_from_pickle(pickle)
parent_lines = gherkin_query.scenario_parent_locations(pickle.ast_node_ids[0]).map(&:line)
Test::Location.new(pickle.uri, parent_lines)
end

def source_lines_for_all_pickle_tags(pickle, uri)
pickle.tags.map { |tag| Test::Tag.new(Test::Location.new(uri, source_line_for_pickle_tag(tag)), tag.name) }
def location_from_pickle_step(pickle_step, uri)
lines = pickle_step.ast_node_ids.map { |id| source_line(id) }
Test::Location.new(uri, lines.sort.reverse)
end

def source_line_for_pickle_tag(tag)
source_line(tag.ast_node_id)
def tags_from_pickle(pickle, uri)
pickle.tags.map do |tag|
location = Test::Location.new(uri, source_line(tag.ast_node_id))
Test::Tag.new(location, tag.name)
end
end

def source_line(id)
gherkin_query.location(id).line
end

def pickle_step_for_doc_string(pickle_step)
def doc_string_from_pickle_step(pickle_step)
doc_string = pickle_step.argument.doc_string
Test::DocString.new(
doc_string.content,
doc_string.media_type
)
end

def pickle_step_for_data_table(pickle_step)
def data_table_from_pickle_step(pickle_step)
data_table = pickle_step.argument.data_table
Test::DataTable.new(
data_table.rows.map do |row|
row.cells.map { |cell| cell.value }
row.cells.map(&:value)
end
)
end
Expand Down
10 changes: 6 additions & 4 deletions lib/cucumber/core/test/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ module Cucumber
module Core
module Test
class Case
attr_reader :id, :name, :test_steps, :location, :tags, :language, :around_hooks
attr_reader :id, :name, :test_steps, :location, :parent_locations, :tags, :language, :around_hooks

def initialize(id, name, test_steps, location, tags, language, around_hooks = [])
def initialize(id, name, test_steps, location, parent_locations, tags, language, around_hooks = [])
Comment thread
luke-hill marked this conversation as resolved.
raise ArgumentError.new("test_steps should be an Array but is a #{test_steps.class}") unless test_steps.is_a?(Array)
@id = id
@name = name
@test_steps = test_steps
@location = location
@parent_locations = parent_locations
@tags = tags
@language = language
@around_hooks = around_hooks
Expand All @@ -36,11 +37,11 @@ def describe_to(visitor, *args)
end

def with_steps(test_steps)
self.class.new(id, name, test_steps, location, tags, language, around_hooks)
self.class.new(id, name, test_steps, location, parent_locations, tags, language, around_hooks)
Comment thread
luke-hill marked this conversation as resolved.
end

def with_around_hooks(around_hooks)
self.class.new(id, name, test_steps, location, tags, language, around_hooks)
self.class.new(id, name, test_steps, location, parent_locations, tags, language, around_hooks)
end

def match_tags?(*expressions)
Expand All @@ -61,6 +62,7 @@ def match_locations?(queried_locations)

def matching_locations
[
parent_locations,
Comment thread
luke-hill marked this conversation as resolved.
location,
tags.map(&:location),
test_steps.map(&:matching_locations)
Expand Down
5 changes: 3 additions & 2 deletions spec/cucumber/core/test/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
let(:id) { double }
let(:name) { double }
let(:location) { double }
let(:parent_locations) { double }
let(:tags) { double }
let(:language) { double }
let(:test_case) { described_class.new(id, name, test_steps, location, tags, language) }
let(:test_case) { described_class.new(id, name, test_steps, location, parent_locations, tags, language) }
let(:test_steps) { [double, double] }

context 'describing itself' do
Expand All @@ -42,7 +43,7 @@
expect(first_hook).to receive(:describe_to).ordered.and_yield
expect(second_hook).to receive(:describe_to).ordered.and_yield
around_hooks = [first_hook, second_hook]
described_class.new(id, name, [], location, tags, language, around_hooks).describe_to(visitor, double)
described_class.new(id, name, [], location, parent_locations, tags, language, around_hooks).describe_to(visitor, double)
end
end

Expand Down
Loading