diff --git a/lib/cucumber/events/base.rb b/lib/cucumber/events/base.rb new file mode 100644 index 000000000..3593c7c58 --- /dev/null +++ b/lib/cucumber/events/base.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Cucumber + module Events + # An archetype of what each Cucumber Event defined in cucumber-ruby must adhere to + class Base + # The "key" name of the class to be used as the key in the event registry (Underscored name symbolized) + # @return [Symbol] + def self.event_id + raise 'Must be implemented in subclass' + end + + # The properties of each event. Stored in iVar named format - where the key is the name of the iVar + # @return [Hash] + def to_h + instance_variables.to_h { |variable_name| [variable_name[1..].to_sym, instance_variable_get(variable_name)] } + end + + def event_id + self.class.event_id + end + end + end +end diff --git a/lib/cucumber/events/envelope.rb b/lib/cucumber/events/envelope.rb index ab2fbf399..fe98ccf0f 100644 --- a/lib/cucumber/events/envelope.rb +++ b/lib/cucumber/events/envelope.rb @@ -1,12 +1,23 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events - class Envelope < Core::Event.new(:envelope) + class Envelope < Base attr_reader :envelope + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :envelope + end + + def initialize(envelope) + @envelope = envelope + super() + end + def inspect "Envelope Event -> Message Type: #{type}}" end diff --git a/lib/cucumber/events/gherkin_source_parsed.rb b/lib/cucumber/events/gherkin_source_parsed.rb index c5d7d6691..125190d83 100644 --- a/lib/cucumber/events/gherkin_source_parsed.rb +++ b/lib/cucumber/events/gherkin_source_parsed.rb @@ -1,13 +1,24 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Fired after we've parsed the contents of a feature file - class GherkinSourceParsed < Core::Event.new(:gherkin_document) - # The Gherkin Ast + class GherkinSourceParsed < Base + # # The Gherkin Ast attr_reader :gherkin_document + + # The underscored name of the class to be used as the key in an event registry + # @return [Symb + def self.event_id + :gherkin_source_parsed + end + + def initialize(gherkin_document) + @gherkin_document = gherkin_document + super() + end end end end diff --git a/lib/cucumber/events/gherkin_source_read.rb b/lib/cucumber/events/gherkin_source_read.rb index 5ff1ab282..8df4a69d6 100644 --- a/lib/cucumber/events/gherkin_source_read.rb +++ b/lib/cucumber/events/gherkin_source_read.rb @@ -1,16 +1,26 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events # Fired after we've read in the contents of a feature file - class GherkinSourceRead < Core::Event.new(:path, :body) + class GherkinSourceRead < Base # The path to the file attr_reader :path # The raw Gherkin source attr_reader :body + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :gherkin_source_read + end + + def initialize(path, body) + @path = path + @body = body + super() + end end end end diff --git a/lib/cucumber/events/hook_test_step_created.rb b/lib/cucumber/events/hook_test_step_created.rb index 4e1596dcb..5814afa94 100644 --- a/lib/cucumber/events/hook_test_step_created.rb +++ b/lib/cucumber/events/hook_test_step_created.rb @@ -1,12 +1,24 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Event fired when a step is created from a hook - class HookTestStepCreated < Core::Event.new(:test_step, :hook) + class HookTestStepCreated < Base attr_reader :test_step, :hook + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :hook_test_step_created + end + + def initialize(test_step, hook) + @test_step = test_step + @hook = hook + super() + end end end end diff --git a/lib/cucumber/events/step_activated.rb b/lib/cucumber/events/step_activated.rb index e9a26ce4e..6f2fc1ba9 100644 --- a/lib/cucumber/events/step_activated.rb +++ b/lib/cucumber/events/step_activated.rb @@ -1,20 +1,28 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events # Event fired when a step is activated - class StepActivated < Core::Event.new(:test_step, :step_match) + class StepActivated < Base # The test step that was matched. - # - # @return [Cucumber::Core::Test::Step] + # @return [Cucumber::Core::Test::Step] attr_reader :test_step # Information about the matching definition. - # - # @return [Cucumber::StepMatch] + # @return [Cucumber::StepMatch] attr_reader :step_match + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :step_activated + end + + def initialize(test_step, step_match) + @test_step = test_step + @step_match = step_match + super() + end end end end diff --git a/lib/cucumber/events/step_definition_registered.rb b/lib/cucumber/events/step_definition_registered.rb index 4770b889c..31746394d 100644 --- a/lib/cucumber/events/step_definition_registered.rb +++ b/lib/cucumber/events/step_definition_registered.rb @@ -1,15 +1,25 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Event fired after each step definition has been registered - class StepDefinitionRegistered < Core::Event.new(:step_definition) + class StepDefinitionRegistered < Base # The step definition that was just registered. - # - # @return [RbSupport::RbStepDefinition] + # @return [RbSupport::RbStepDefinition] attr_reader :step_definition + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :step_definition_registered + end + + def initialize(step_definition) + @step_definition = step_definition + super() + end end end end diff --git a/lib/cucumber/events/test_case_created.rb b/lib/cucumber/events/test_case_created.rb index c23e2a9d6..f93717e38 100644 --- a/lib/cucumber/events/test_case_created.rb +++ b/lib/cucumber/events/test_case_created.rb @@ -1,12 +1,22 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events # Event fired when a Test::Case is created from a Pickle - class TestCaseCreated < Core::Event.new(:test_case, :pickle) + class TestCaseCreated < Base attr_reader :test_case, :pickle + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :test_case_created + end + + def initialize(test_case, pickle) + @test_case = test_case + @pickle = pickle + super() + end end end end diff --git a/lib/cucumber/events/test_case_finished.rb b/lib/cucumber/events/test_case_finished.rb index 0083203f0..1c5566e8c 100644 --- a/lib/cucumber/events/test_case_finished.rb +++ b/lib/cucumber/events/test_case_finished.rb @@ -1,16 +1,26 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events - # Signals that a {Cucumber::Core::Test::Case} has finished executing - class TestCaseFinished < Core::Events::TestCaseFinished + # Event fired when a Test::Case is created from a Pickle + class TestCaseFinished < Base # @return [Cucumber::Core::Test::Case] that was executed attr_reader :test_case # @return [Cucumber::Core::Test::Result] the result of running the {Cucumber::Core::Test::Case} attr_reader :result + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :test_case_finished + end + + def initialize(test_case, result) + @test_case = test_case + @result = result + super() + end end end end diff --git a/lib/cucumber/events/test_case_ready.rb b/lib/cucumber/events/test_case_ready.rb index 3ffa86fb6..71d804ecb 100644 --- a/lib/cucumber/events/test_case_ready.rb +++ b/lib/cucumber/events/test_case_ready.rb @@ -1,12 +1,20 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events - # Event fired when a Test::Case is ready to be ran (matching has been done, hooks added etc) - class TestCaseReady < Core::Event.new(:test_case) + class TestCaseReady < Base attr_reader :test_case + + # The underscored name of the class to be used as the key in an event registry + # @return [Symbol] + def self.event_id + :test_case_ready + end + + def initialize(test_case) + @test_case = test_case + super() + end end end end diff --git a/lib/cucumber/events/test_case_started.rb b/lib/cucumber/events/test_case_started.rb index 75e247286..d19b56fd8 100644 --- a/lib/cucumber/events/test_case_started.rb +++ b/lib/cucumber/events/test_case_started.rb @@ -1,13 +1,22 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Signals that a {Cucumber::Core::Test::Case} is about to be executed - class TestCaseStarted < Core::Events::TestCaseStarted + class TestCaseStarted < Base # @return [Cucumber::Core::Test::Case] the test case to be executed attr_reader :test_case + + def self.event_id + :test_case_started + end + + def initialize(test_case) + @test_case = test_case + super() + end end end end diff --git a/lib/cucumber/events/test_run_finished.rb b/lib/cucumber/events/test_run_finished.rb index 67c607e4c..7db6ffbb8 100644 --- a/lib/cucumber/events/test_run_finished.rb +++ b/lib/cucumber/events/test_run_finished.rb @@ -1,12 +1,19 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events # Event fired after all test cases have finished executing - class TestRunFinished < Core::Event.new(:success) + class TestRunFinished < Base attr_reader :success + + def self.event_id + :test_run_finished + end + + def initialize(success = nil) + @success = success + super() + end end end end diff --git a/lib/cucumber/events/test_run_hook_finished.rb b/lib/cucumber/events/test_run_hook_finished.rb index 31efc6317..615f5161c 100644 --- a/lib/cucumber/events/test_run_hook_finished.rb +++ b/lib/cucumber/events/test_run_hook_finished.rb @@ -1,11 +1,19 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events - class TestRunHookFinished < Core::Event.new(:hook, :test_result) + class TestRunHookFinished < Base attr_reader :hook, :test_result + + def self.event_id + :test_run_hook_finished + end + + def initialize(hook, test_result) + @hook = hook + @test_result = test_result + super() + end end end end diff --git a/lib/cucumber/events/test_run_hook_started.rb b/lib/cucumber/events/test_run_hook_started.rb index 43577ffad..7847d06d5 100644 --- a/lib/cucumber/events/test_run_hook_started.rb +++ b/lib/cucumber/events/test_run_hook_started.rb @@ -4,8 +4,17 @@ module Cucumber module Events - class TestRunHookStarted < Core::Event.new(:hook) + class TestRunHookStarted < Base attr_reader :hook + + def self.event_id + :test_run_hook_started + end + + def initialize(hook) + @hook = hook + super() + end end end end diff --git a/lib/cucumber/events/test_run_started.rb b/lib/cucumber/events/test_run_started.rb index 638cf7ec2..03a94e19e 100644 --- a/lib/cucumber/events/test_run_started.rb +++ b/lib/cucumber/events/test_run_started.rb @@ -1,14 +1,23 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Event fired once all test cases have been filtered before # the first one is executed. - class TestRunStarted < Core::Event.new(:test_cases) + class TestRunStarted < Base # @return [Array] the test cases to be executed attr_reader :test_cases + + def self.event_id + :test_run_started + end + + def initialize(test_cases) + @test_cases = test_cases + super() + end end end end diff --git a/lib/cucumber/events/test_step_created.rb b/lib/cucumber/events/test_step_created.rb index 577d8f831..0d15af4dc 100644 --- a/lib/cucumber/events/test_step_created.rb +++ b/lib/cucumber/events/test_step_created.rb @@ -1,12 +1,22 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Event fired when a TestStep is created from a PickleStep - class TestStepCreated < Core::Event.new(:test_step, :pickle_step) + class TestStepCreated < Base attr_reader :test_step, :pickle_step + + def self.event_id + :test_step_created + end + + def initialize(test_step, pickle_step) + @test_step = test_step + @pickle_step = pickle_step + super() + end end end end diff --git a/lib/cucumber/events/test_step_finished.rb b/lib/cucumber/events/test_step_finished.rb index bf7319955..7c8dc8478 100644 --- a/lib/cucumber/events/test_step_finished.rb +++ b/lib/cucumber/events/test_step_finished.rb @@ -1,16 +1,26 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Signals that a {Cucumber::Core::Test::Step} has finished executing - class TestStepFinished < Core::Events::TestStepFinished + class TestStepFinished < Base # @return [Cucumber::Core::Test::Step] the test step that was executed attr_reader :test_step # @return [Cucumber::Core::Test::Result] the result of running the {Cucumber::Core::Test::Step} attr_reader :result + + def self.event_id + :test_step_finished + end + + def initialize(test_step, result) + @test_step = test_step + @result = result + super() + end end end end diff --git a/lib/cucumber/events/test_step_started.rb b/lib/cucumber/events/test_step_started.rb index 9758694a6..ca0b22ce4 100644 --- a/lib/cucumber/events/test_step_started.rb +++ b/lib/cucumber/events/test_step_started.rb @@ -1,13 +1,22 @@ # frozen_string_literal: true -require 'cucumber/core/events' +require_relative 'base' module Cucumber module Events # Signals that a {Cucumber::Core::Test::Step} is about to be executed - class TestStepStarted < Core::Events::TestStepStarted + class TestStepStarted < Base # @return [Cucumber::Core::Test::Step] the test step to be executed attr_reader :test_step + + def self.event_id + :test_step_started + end + + def initialize(test_step) + @test_step = test_step + super() + end end end end diff --git a/lib/cucumber/events/undefined_parameter_type.rb b/lib/cucumber/events/undefined_parameter_type.rb index bb52281a4..b48d46324 100644 --- a/lib/cucumber/events/undefined_parameter_type.rb +++ b/lib/cucumber/events/undefined_parameter_type.rb @@ -1,11 +1,19 @@ # frozen_string_literal: true -require 'cucumber/core/events' - module Cucumber module Events - class UndefinedParameterType < Core::Event.new(:type_name, :expression) + class UndefinedParameterType < Base attr_reader :type_name, :expression + + def self.event_id + :undefined_parameter_type + end + + def initialize(type_name, expression) + @type_name = type_name + @expression = expression + super() + end end end end diff --git a/lib/cucumber/formatter/fail_fast.rb b/lib/cucumber/formatter/fail_fast.rb index 3ebac8acf..60ba4f08d 100644 --- a/lib/cucumber/formatter/fail_fast.rb +++ b/lib/cucumber/formatter/fail_fast.rb @@ -9,11 +9,10 @@ class FailFast def initialize(configuration) @previous_test_case = nil configuration.on_event :test_case_finished do |event| - test_case, result = *event.attributes - if test_case != @previous_test_case + if event.test_case != @previous_test_case @previous_test_case = event.test_case - Cucumber.wants_to_quit = true unless result.ok?(strict: configuration.strict) - elsif result.passed? + Cucumber.wants_to_quit = true unless event.result.ok?(strict: configuration.strict) + elsif event.result.passed? Cucumber.wants_to_quit = false end end diff --git a/lib/cucumber/formatter/json.rb b/lib/cucumber/formatter/json.rb index 8fc8471a4..731ed8ff1 100644 --- a/lib/cucumber/formatter/json.rb +++ b/lib/cucumber/formatter/json.rb @@ -65,7 +65,8 @@ def on_test_step_started(event) end def on_test_step_finished(event) - test_step, result = *event.attributes + test_step = event.test_step + result = event.result result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter) return if internal_hook?(test_step) @@ -76,7 +77,8 @@ def on_test_step_finished(event) def on_test_case_finished(event) feature_elements << @test_case_hash if @in_background - _test_case, result = *event.attributes + _test_case = event.test_case + result = event.result result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter) add_failed_around_hook(result) if result.failed? && !@any_step_failed end diff --git a/lib/cucumber/formatter/junit.rb b/lib/cucumber/formatter/junit.rb index f4f9dba47..9cb07ff57 100644 --- a/lib/cucumber/formatter/junit.rb +++ b/lib/cucumber/formatter/junit.rb @@ -51,19 +51,17 @@ def on_test_case_started(event) end def on_test_step_finished(event) - test_step, result = *event.attributes return if @failing_test_step - @failing_test_step = test_step unless result.ok?(strict: @config.strict) + @failing_test_step = event.test_step unless event.result.ok?(strict: @config.strict) end def on_test_case_finished(event) - test_case, result = *event.attributes - result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter) - test_case_name = NameBuilder.new(test_case, @ast_lookup) + result = event.result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter) + test_case_name = NameBuilder.new(event.test_case, @ast_lookup) scenario = test_case_name.scenario_name scenario_designation = "#{scenario}#{test_case_name.name_suffix}" - output = create_output_string(test_case, scenario, result, test_case_name.row_name) + output = create_output_string(event.test_case, scenario, result, test_case_name.row_name) build_testcase(result, scenario_designation, output) Interceptor::Pipe.unwrap! :stdout diff --git a/lib/cucumber/formatter/pretty.rb b/lib/cucumber/formatter/pretty.rb index 97ba8d796..a660d05c2 100644 --- a/lib/cucumber/formatter/pretty.rb +++ b/lib/cucumber/formatter/pretty.rb @@ -73,8 +73,7 @@ def on_gherkin_source_read(event) end def on_step_activated(event) - test_step, step_match = *event.attributes - @step_matches[test_step.to_s] = step_match + @step_matches[event.test_step.to_s] = event.step_match end def on_test_case_started(event) diff --git a/lib/cucumber/formatter/usage.rb b/lib/cucumber/formatter/usage.rb index 6852e0791..f17680ff4 100644 --- a/lib/cucumber/formatter/usage.rb +++ b/lib/cucumber/formatter/usage.rb @@ -32,8 +32,7 @@ def initialize(config) @total_duration = 0 @matches = {} config.on_event :step_activated do |event| - test_step, step_match = *event.attributes - @matches[test_step.to_s] = step_match + @matches[event.test_step.to_s] = event.step_match end config.on_event :step_definition_registered, &method(:on_step_definition_registered) end diff --git a/lib/cucumber/glue/registry_and_more.rb b/lib/cucumber/glue/registry_and_more.rb index f042c027a..d678735d4 100644 --- a/lib/cucumber/glue/registry_and_more.rb +++ b/lib/cucumber/glue/registry_and_more.rb @@ -13,6 +13,7 @@ require 'cucumber/gherkin/i18n' require 'multi_test' require 'cucumber/step_match' +require 'cucumber/events/base' require 'cucumber/events/step_definition_registered' module Cucumber