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
35 changes: 26 additions & 9 deletions lib/cucumber/formatter/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require 'base64'
require 'cucumber/formatter/backtrace_filter'
require 'cucumber/formatter/query/hook_by_test_step'
require 'cucumber/formatter/query/pickle_by_test'
require 'cucumber/formatter/query/step_definitions_by_test_step'
require 'cucumber/formatter/query/test_case_started_by_test_case'

Expand All @@ -18,17 +16,19 @@ class MessageBuilder
def initialize(config)
@config = config

@hook_by_test_step = Query::HookByTestStep.new(config)
@pickle_by_test = Query::PickleByTest.new(config)
@step_definitions_by_test_step = Query::StepDefinitionsByTestStep.new(config)
@test_case_started_by_test_case = Query::TestCaseStartedByTestCase.new(config)

@repository = Cucumber::Repository.new
@query = Cucumber::Query.new(@repository)

@test_run_started_id = config.id_generator.new_id

# Fake Query objects
@test_case_by_step_id = {}
@pickle_id_by_test_case_id = {}
@pickle_id_step_by_test_step_id = {}
@hook_id_by_test_step_id = {}

# Ensure all handlers for events occur after all ivars are instantiated

Expand All @@ -42,7 +42,7 @@ def initialize(config)
config.on_event :step_activated, &method(:on_step_activated)
config.on_event :step_definition_registered, &method(:on_step_definition_registered)

# TODO: Handle TestCaseCreated
config.on_event :test_case_created, &method(:on_test_case_created)
config.on_event :test_case_ready, &method(:on_test_case_ready)
config.on_event :test_case_started, &method(:on_test_case_started)
config.on_event :test_case_finished, &method(:on_test_case_finished)
Expand Down Expand Up @@ -104,15 +104,19 @@ def on_gherkin_source_read(event)
output_envelope(message)
end

def on_hook_test_step_created(_event)
# TODO: Handle HookTestStepCreated
def on_hook_test_step_created(event)
@hook_id_by_test_step_id[event.test_step.id] = event.hook.id
end

def on_test_case_created(event)
@pickle_id_by_test_case_id[event.test_case.id] = event.pickle.id
end

def on_test_case_ready(event)
message = Cucumber::Messages::Envelope.new(
test_case: Cucumber::Messages::TestCase.new(
id: event.test_case.id,
pickle_id: @pickle_by_test.pickle_id(event.test_case),
pickle_id: fake_query_pickle_id(event.test_case),
test_steps: event.test_case.test_steps.map { |step| test_step_to_message(step) },
test_run_started_id: @test_run_started_id
)
Expand Down Expand Up @@ -146,7 +150,7 @@ def test_step_to_message(step)
def hook_step_to_message(step)
Cucumber::Messages::TestStep.new(
id: step.id,
hook_id: @hook_by_test_step.hook_id(step)
hook_id: fake_query_hook_id(step)
)
end

Expand Down Expand Up @@ -209,6 +213,7 @@ def on_test_case_started(event)
def on_test_step_created(event)
@pickle_id_step_by_test_step_id[event.test_step.id] = event.pickle_step.id
test_step_to_message(event.test_step)
@hook_id_by_test_step_id[event.test_step.id] = nil
# TODO: We need to determine what message to output here (Unsure - Placeholder added)
# message = Cucumber::Messages::Envelope.new(
# pickle: {
Expand Down Expand Up @@ -378,6 +383,18 @@ def on_undefined_parameter_type(event)
def test_case_started_id(test_case)
@test_case_started_by_test_case.test_case_started_id_by_test_case(test_case)
end

def fake_query_hook_id(test_step)
return @hook_id_by_test_step_id[test_step.id] if @hook_id_by_test_step_id.key?(test_step.id)

raise TestStepUnknownError, "No hook found for #{test_step.id} }. Known: #{@hook_id_by_test_step_id.keys}"
end

def fake_query_pickle_id(test_case)
return @pickle_id_by_test_case_id[test_case.id] if @pickle_id_by_test_case_id.key?(test_case.id)

raise TestCaseUnknownError, "No pickle found for #{test_case.id} }. Known: #{@pickle_id_by_test_case_id.keys}"
end
end
end
end
34 changes: 0 additions & 34 deletions lib/cucumber/formatter/query/hook_by_test_step.rb

This file was deleted.

28 changes: 0 additions & 28 deletions lib/cucumber/formatter/query/pickle_by_test.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/cucumber/formatter/query/step_definitions_by_test_step.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Cucumber
module Formatter
module Query
class StepDefinitionsByTestStep
attr_reader :step_definition_ids_by_test_step_id, :step_match_arguments_by_test_step_id

def initialize(config)
@step_definition_ids_by_test_step_id = {}
@step_match_arguments_by_test_step_id = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Cucumber
module Formatter
module Query
class TestCaseStartedByTestCase
attr_reader :attempts_by_test_case_id, :test_case_started_id_by_test_case_id

def initialize(config)
@config = config
config.on_event :test_case_created, &method(:on_test_case_created)
Expand Down
93 changes: 0 additions & 93 deletions spec/cucumber/formatter/query/hook_by_test_step_spec.rb

This file was deleted.

63 changes: 0 additions & 63 deletions spec/cucumber/formatter/query/pickle_by_test_spec.rb

This file was deleted.