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
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
- Refactored the internal base `Event` class to reduce complexity and make it more flexible for future use (No user facing changes)

## [16.2.0] - 2026-02-06
### Changed
Expand Down
22 changes: 12 additions & 10 deletions lib/cucumber/core/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ def self.new(*events)
instance_variable_set(:"@#{name}", value)
end
end
end
end

define_method(:attributes) do
events.map { |var| instance_variable_get(:"@#{var}") }
end
def to_h
instance_variables.to_h do |variable_name|
[variable_name[1..].to_sym, instance_variable_get(variable_name)]
end
end

define_method(:to_h) do
events.zip(attributes).to_h
end
def attributes
instance_variables.map { |var| instance_variable_get(var) }
end

def event_id
self.class.event_id
end
end
def event_id
self.class.event_id
end

class << self
Expand Down
1 change: 0 additions & 1 deletion lib/cucumber/core/events/envelope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Cucumber
module Core
module Events
class Envelope < Event.new(:envelope)
attr_reader :envelope
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/cucumber/core/events/gherkin_source_parsed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ module Core
module Events
# Signals that a gherkin source has been parsed
class GherkinSourceParsed < Event.new(:gherkin_document)
# @return [GherkinDocument] the GherkinDocument Ast Node
attr_reader :gherkin_document
# @return [GherkinDocument] the GherkinDocument Ast Node that was parsed
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions lib/cucumber/core/events/test_case_created.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ module Core
module Events
# Signals that a Test::Case was created from a Pickle
class TestCaseCreated < Event.new(:test_case, :pickle)
# The created test step
attr_reader :test_case

# The source pickle step
attr_reader :pickle
# The created test step & source pickle
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/cucumber/core/events/test_case_finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ module Events
# Signals that a {Test::Case} has finished executing
class TestCaseFinished < Event.new(:test_case, :result)
# @return [Test::Case] that was executed
attr_reader :test_case

# @return [Test::Result] the result of running the {Test::Step}
attr_reader :result
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/cucumber/core/events/test_case_started.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Events
# Signals that a {Test::Case} is about to be executed
class TestCaseStarted < Event.new(:test_case)
# @return [Test::Case] the test case to be executed
attr_reader :test_case
end
end
end
Expand Down
6 changes: 1 addition & 5 deletions lib/cucumber/core/events/test_step_created.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ module Core
module Events
# Signals that a Test::Step was created from a PickleStep
class TestStepCreated < Event.new(:test_step, :pickle_step)
# The created test step
attr_reader :test_step

# The source pickle step
attr_reader :pickle_step
# The created test step & source pickle step
end
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/cucumber/core/events/test_step_finished.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ module Events
# Signals that a {Test::Step} has finished executing
class TestStepFinished < Event.new(:test_step, :result)
# @return [Test::Step] the test step that was executed
attr_reader :test_step

# @return [Test::Result] the result of running the {Test::Step}
attr_reader :result
end
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/cucumber/core/events/test_step_started.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Events
# Signals that a {Test::Step} is about to be executed
class TestStepStarted < Event.new(:test_step)
# @return [Test::Step] the test step to be executed
attr_reader :test_step
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions spec/cucumber/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@
observed_events << [:test_case_started, test_case.name]
end
event_bus.on(:test_case_finished) do |event|
test_case, result = *event.attributes
test_case = event.test_case
result = event.result
observed_events << [:test_case_finished, test_case.name, result.to_sym]
end
event_bus.on(:test_step_started) do |event|
test_step = event.test_step
observed_events << [:test_step_started, test_step.text]
end
event_bus.on(:test_step_finished) do |event|
test_step, result = *event.attributes
test_step = event.test_step
result = event.result
observed_events << [:test_step_finished, test_step.text, result.to_sym]
end
end
Expand Down