Skip to content
Open
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
24 changes: 24 additions & 0 deletions lib/cucumber/events/base.rb
Original file line number Diff line number Diff line change
@@ -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<Symbol>]
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
15 changes: 13 additions & 2 deletions lib/cucumber/events/envelope.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 14 additions & 3 deletions lib/cucumber/events/gherkin_source_parsed.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions lib/cucumber/events/gherkin_source_read.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions lib/cucumber/events/hook_test_step_created.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 15 additions & 7 deletions lib/cucumber/events/step_activated.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 14 additions & 4 deletions lib/cucumber/events/step_definition_registered.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions lib/cucumber/events/test_case_created.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 14 additions & 4 deletions lib/cucumber/events/test_case_finished.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions lib/cucumber/events/test_case_ready.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions lib/cucumber/events/test_case_started.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 10 additions & 3 deletions lib/cucumber/events/test_run_finished.rb
Original file line number Diff line number Diff line change
@@ -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
14 changes: 11 additions & 3 deletions lib/cucumber/events/test_run_hook_finished.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion lib/cucumber/events/test_run_hook_started.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 11 additions & 2 deletions lib/cucumber/events/test_run_started.rb
Original file line number Diff line number Diff line change
@@ -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<Cucumber::Core::Test::Case>] 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
Loading
Loading