Skip to content
61 changes: 25 additions & 36 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2026-06-01 22:49:40 UTC using RuboCop version 1.87.0.
# on 2026-06-02 19:13:42 UTC using RuboCop version 1.87.0.
# 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
Expand All @@ -12,6 +12,12 @@
# TODO: [LH] v16.2 (Generic refactors / new events) -> 79 files inspected, 222 offenses detected, 10 offenses autocorrectable
# TODO: [LH] v17 prep -> 92 files inspected, 212 offenses detected, 10 offenses autocorrectable

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Layout/SpaceAroundMethodCallOperator:
Exclude:
- 'spec/cucumber/core/test/result_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Lint/RedundantRequireStatement:
Expand All @@ -23,33 +29,40 @@ Lint/RedundantRequireStatement:
Metrics/AbcSize:
Max: 21

# Offense count: 3
# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 28

# Offense count: 4
# Offense count: 3
# Configuration parameters: CountComments, CountAsOne.
Metrics/ModuleLength:
Max: 346
Max: 110

# Offense count: 1
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
Metrics/ParameterLists:
Max: 8

# Offense count: 2
# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
RSpec/EmptyExampleGroup:
Exclude:
- 'spec/cucumber/core/compiler_spec.rb'
- 'spec/cucumber/core/gherkin/writer_spec.rb'

# Offense count: 38
# Offense count: 21
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 11

# Offense count: 24
# Offense count: 1
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/cucumber/core/test/result_spec.rb'

# Offense count: 23
RSpec/MissingExampleGroupArgument:
Exclude:
- 'spec/cucumber/core/compiler_spec.rb'
Expand All @@ -60,21 +73,21 @@ RSpec/MissingExampleGroupArgument:
- 'spec/cucumber/core/test/locations_filter_spec.rb'
- 'spec/cucumber/core_spec.rb'

# Offense count: 69
# Offense count: 66
RSpec/MultipleExpectations:
Max: 5

# Offense count: 48
# Offense count: 53
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 11

# Offense count: 8
# Offense count: 13
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4
Max: 5

# Offense count: 23
# Offense count: 22
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: ^expect_, ^assert_
RSpec/NoExpectationExample:
Expand Down Expand Up @@ -105,27 +118,3 @@ RSpec/RepeatedExample:
Style/AccessModifierDeclarations:
Exclude:
- 'lib/cucumber/core/filter.rb'

# Offense count: 3
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, AllowedParentClasses.
# SupportedStyles: class_keyword, class_new, class_definition
Style/EmptyClassDefinition:
Exclude:
- 'lib/cucumber/core/gherkin/parser.rb'
- 'lib/cucumber/core/test/location.rb'
- 'spec/support/activate_steps_for_self_test.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedMethods, AllowedPatterns.
Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'lib/cucumber/core/test/timer.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: PreferredDelimiters.
Style/PercentLiteralDelimiters:
Exclude:
- 'lib/cucumber/core/test/data_table.rb'
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.

## [Unreleased]
### Changed
- Tidied up a bunch of mostly internal test code to be more rubocop compliant

## [17.0.0] - 2026-06-01
### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/cucumber/core/gherkin/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Cucumber
module Core
module Gherkin
ParseError = Class.new(StandardError)
class ParseError < StandardError; end

class Parser
attr_reader :receiver, :event_bus, :gherkin_query
Expand Down
23 changes: 23 additions & 0 deletions lib/cucumber/core/gherkin/writer/accepts_comments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Cucumber
module Core
module Gherkin
module Writer
module AcceptsComments
def comment(line)
comment_lines << "# #{line}"
end

def comment_lines
@comment_lines ||= []
end

def slurp_comments
comment_lines.tap { @comment_lines = nil }
end
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/cucumber/core/gherkin/writer/background.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class Background
include HasElements
include HasOptionsInitializer
include HasDescription
include Indentation.level 2
extend Indentation

indentation_level 2

default_keyword 'Background'

Expand Down
4 changes: 3 additions & 1 deletion lib/cucumber/core/gherkin/writer/doc_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module Core
module Gherkin
module Writer
class DocString
include Indentation.level(6)
extend Indentation

indentation_level 6

attr_reader :strings, :content_type
private :strings, :content_type
Expand Down
4 changes: 3 additions & 1 deletion lib/cucumber/core/gherkin/writer/example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ module Core
module Gherkin
module Writer
class Example < Scenario
include Indentation.level 4
extend Indentation

indentation_level 4

default_keyword 'Example'
end
Expand Down
4 changes: 3 additions & 1 deletion lib/cucumber/core/gherkin/writer/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Examples
include HasOptionsInitializer
include HasRows
include HasDescription
include Indentation.level(4)
extend Indentation

indentation_level 4

default_keyword 'Examples'

Expand Down
4 changes: 3 additions & 1 deletion lib/cucumber/core/gherkin/writer/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Feature
include HasElements
include HasOptionsInitializer
include HasDescription
include Indentation.level(0)
extend Indentation

indentation_level 0

default_keyword 'Feature'

Expand Down
21 changes: 21 additions & 0 deletions lib/cucumber/core/gherkin/writer/has_description.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module Cucumber
module Core
module Gherkin
module Writer
module HasDescription
private

def description
options.fetch(:description, '').split("\n").map(&:strip)
end

def description_statement
description.map { |s| indent(s, 2) } unless description.empty?
end
end
end
end
end
end
47 changes: 47 additions & 0 deletions lib/cucumber/core/gherkin/writer/has_elements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

module Cucumber
module Core
module Gherkin
module Writer
module HasElements
include AcceptsComments

def self.included(base)
base.extend HasElementBuilders
end

def build(source = [])
elements.inject(source + statements) { |acc, el| el.build(acc) }
end

private

def elements
@elements ||= []
end

module HasElementBuilders
def elements(*names)
names.each { |name| element(name) }
end

private

def element(name)
define_method(name) do |*args, &source|
factory_name = String(name).split('_').map(&:capitalize).join
factory = Writer.const_get(factory_name)
factory.new(slurp_comments, *args).tap do |builder|
builder.instance_exec(&source) if source
elements << builder
end
self
end
end
end
end
end
end
end
end
58 changes: 58 additions & 0 deletions lib/cucumber/core/gherkin/writer/has_options_initializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

module Cucumber
module Core
module Gherkin
module Writer
module HasOptionsInitializer
def self.included(base)
base.extend HasDefaultKeyword
end

attr_reader :name, :options
private :name, :options

def initialize(*args)
@comments = args.shift if args.first.is_a?(Array)
@comments ||= []
@options = args.pop if args.last.is_a?(Hash)
@options ||= {}
@name = args.first
end

private

def comments_statement
@comments
end

def keyword
options.fetch(:keyword) { self.class.keyword }
end

def name_statement
"#{keyword}: #{name}".strip
end

def tag_statement
tags
end

def tags
options[:tags]
end

module HasDefaultKeyword
def default_keyword(keyword)
@keyword = keyword
end

def keyword
@keyword
end
end
end
end
end
end
end
43 changes: 43 additions & 0 deletions lib/cucumber/core/gherkin/writer/has_rows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

module Cucumber
module Core
module Gherkin
module Writer
module HasRows
def row(*cells)
rows << cells
end

def rows
@rows ||= []
end

private

def row_statements(indent = nil)
rows.map { |row| indent(table_row(row), indent) }
end

def table_row(row)
padded = pad(row)
"| #{padded.join(' | ')} |"
end

def pad(row)
row.map.with_index { |text, position| justify_cell(text, position) }
end

def column_length(column)
lengths = rows.transpose.map { |r| r.map(&:length).max }
lengths[column]
end

def justify_cell(cell, position)
cell.ljust(column_length(position))
end
end
end
end
end
end
Loading
Loading