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
11 changes: 7 additions & 4 deletions lib/cucumber/formatter/message.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
# frozen_string_literal: true

require 'cucumber/formatter/io'
require 'cucumber/formatter/message_builder'
require 'cucumber/query'

module Cucumber
module Formatter
# The formatter used for <tt>--format message</tt>
class Message < MessageBuilder
class Message
include Io

def initialize(config)
@io = ensure_io(config.out_stream, config.error_stream)
super(config)
@repository = Cucumber::Repository.new
@query = Cucumber::Query.new(@repository)
config.on_event :envelope, &method(:output_envelope)
end

def output_envelope(envelope)
def output_envelope(event)
envelope = event.envelope
@repository.update(envelope)
@io.write(envelope.to_json)
@io.write("\n")
Expand Down
38 changes: 13 additions & 25 deletions lib/cucumber/formatter/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
require 'base64'
require 'cucumber/formatter/backtrace_filter'

require 'cucumber/query'

module Cucumber
module Formatter
class MessageBuilder
Expand All @@ -14,7 +12,6 @@ class MessageBuilder
def initialize(config)
@config = config
@repository = Cucumber::Repository.new
@query = Cucumber::Query.new(@repository)

@test_run_started_id = config.id_generator.new_id

Expand All @@ -27,15 +24,13 @@ def initialize(config)
@step_match_arguments_by_test_step_id = {}

# Ensure all handlers for events occur after all ivars are instantiated
config.on_event :envelope, &method(:on_envelope)

config.on_event :gherkin_source_parsed, &method(:on_gherkin_source_parsed)
config.on_event :gherkin_source_read, &method(:on_gherkin_source_read)

config.on_event :hook_test_step_created, &method(:on_hook_test_step_created)

config.on_event :step_activated, &method(:on_step_activated)
config.on_event :step_definition_registered, &method(:on_step_definition_registered)

config.on_event :test_case_created, &method(:on_test_case_created)
config.on_event :test_case_ready, &method(:on_test_case_ready)
Expand Down Expand Up @@ -74,15 +69,11 @@ def attach(src, media_type, filename)
end

message = Cucumber::Messages::Envelope.new(attachment: Cucumber::Messages::Attachment.new(**attachment_data))
output_envelope(message)
@config.event_bus.envelope(message)
end

private

def on_envelope(event)
output_envelope(event.envelope)
end

def on_gherkin_source_parsed(_event)
# TODO: Handle GherkinSourceParsed
end
Expand All @@ -96,7 +87,7 @@ def on_gherkin_source_read(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_hook_test_step_created(event)
Expand All @@ -108,10 +99,6 @@ def on_step_activated(event)
@step_match_arguments_by_test_step_id[event.test_step.id] = event.step_match.step_arguments
end

def on_step_definition_registered(event)
output_envelope(event.step_definition.to_envelope)
end

def on_test_case_created(event)
@pickle_id_by_test_case_id[event.test_case.id] = event.pickle.id
end
Expand All @@ -129,7 +116,7 @@ def on_test_case_ready(event)
# TODO: This may be a redundant update. But for now we're leaving this in whilst we're in the transitory phase
@repository.update(message)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_case_started(event)
Expand All @@ -153,7 +140,8 @@ def on_test_case_started(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
@repository.update(message)
end

def on_test_case_finished(event)
Expand All @@ -176,7 +164,7 @@ def on_test_case_finished(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_run_started(*)
Expand All @@ -187,7 +175,7 @@ def on_test_run_started(*)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_run_finished(event)
Expand All @@ -199,7 +187,7 @@ def on_test_run_finished(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_run_hook_started(event)
Expand All @@ -214,7 +202,7 @@ def on_test_run_hook_started(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_run_hook_finished(event)
Expand All @@ -238,7 +226,7 @@ def on_test_run_hook_finished(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_step_created(event)
Expand Down Expand Up @@ -267,7 +255,7 @@ def on_test_step_started(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_test_step_finished(event)
Expand Down Expand Up @@ -305,7 +293,7 @@ def on_test_step_finished(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def on_undefined_parameter_type(event)
Expand All @@ -316,7 +304,7 @@ def on_undefined_parameter_type(event)
)
)

output_envelope(message)
@config.event_bus.envelope(message)
end

def test_step_to_message(step)
Expand Down
14 changes: 10 additions & 4 deletions lib/cucumber/formatter/rerun.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# frozen_string_literal: true

require 'cucumber/formatter/io'
require 'cucumber/formatter/message_builder'
require 'cucumber/query'

module Cucumber
module Formatter
class Rerun < MessageBuilder
class Rerun
include Io

def initialize(config)
@config = config
@io = ensure_io(config.out_stream, config.error_stream)
super(config)
@repository = Cucumber::Repository.new
@query = Cucumber::Query.new(@repository)
config.on_event :envelope, &method(:output_envelope)
end

def output_envelope(envelope)
def output_envelope(event)
envelope = event.envelope
@repository.update(envelope)
finish_report if envelope.test_run_finished
end
Expand Down
1 change: 1 addition & 0 deletions lib/cucumber/glue/registry_and_more.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def register_rb_step_definition(string_or_regexp, proc_or_sym, options)
step_definition = StepDefinition.new(@configuration.id_generator.new_id, self, string_or_regexp, proc_or_sym, options)
@step_definitions << step_definition
@configuration.notify :step_definition_registered, step_definition
@configuration.notify :envelope, step_definition.to_envelope
step_definition
rescue Cucumber::CucumberExpressions::UndefinedParameterTypeError => e
# TODO: add a way to extract the parameter type directly from the error.
Expand Down
6 changes: 5 additions & 1 deletion lib/cucumber/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@ def set_encoding
def report
return @report if @report

reports = [summary_report] + formatters
reports = [message_builder, summary_report] + formatters
reports << fail_fast_report if @configuration.fail_fast?
reports << publish_banner_printer unless @configuration.publish_quiet?
@report ||= Formatter::Fanout.new(reports)
end

def message_builder
@message_builder ||= Formatter::MessageBuilder.new(@configuration)
end

def summary_report
@summary_report ||= Core::Report::Summary.new(@configuration.event_bus)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/cucumber/formatter/rerun_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [gherkin], [StandardStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus
config.event_bus.test_run_finished

Expand Down Expand Up @@ -70,6 +71,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [foo, bar], [StandardStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus
config.event_bus.test_run_finished

Expand All @@ -88,6 +90,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [gherkin], [StandardStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus
config.event_bus.test_run_finished

Expand All @@ -107,6 +110,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [gherkin], [FakeObjects::FlakyStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus

config.event_bus.test_run_finished
Expand All @@ -128,6 +132,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [gherkin], [FakeObjects::FlakyStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus
config.event_bus.test_run_finished

Expand All @@ -144,6 +149,7 @@ module Formatter
end

described_class.new(config)
MessageBuilder.new(config)
execute [gherkin, gherkin], [StandardStepActions.new, Filters::BroadcastTestRunStartedEvent.new(config), Filters::BroadcastTestCaseReadyEvent.new(config)], config.event_bus
config.event_bus.test_run_finished

Expand Down
2 changes: 1 addition & 1 deletion spec/cucumber/formatter/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module SpecHelper

def run_defined_feature
define_steps
actual_runtime.visitor = Fanout.new([@formatter])
actual_runtime.visitor = Fanout.new([actual_runtime.send(:message_builder), @formatter])
receiver = Test::Runner.new(event_bus)

event_bus.gherkin_source_read(gherkin_doc.uri, gherkin_doc.body)
Expand Down
Loading