Class: Cucumber::Formatter::MessageBuilder

Inherits:
Object
  • Object
show all
Includes:
Messages::TimeConversion
Defined in:
lib/cucumber/formatter/message_builder.rb

Direct Known Subclasses

HTML, Message

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ MessageBuilder

Returns a new instance of MessageBuilder.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cucumber/formatter/message_builder.rb', line 16

def initialize(config)
  @config = config

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

  config.on_event :envelope, &method(:on_envelope)
  config.on_event :gherkin_source_read, &method(:on_gherkin_source_read)
  config.on_event :test_case_ready, &method(:on_test_case_ready)
  config.on_event :test_run_started, &method(:on_test_run_started)
  config.on_event :test_case_started, &method(:on_test_case_started)
  config.on_event :test_step_started, &method(:on_test_step_started)
  config.on_event :test_step_finished, &method(:on_test_step_finished)
  config.on_event :test_case_finished, &method(:on_test_case_finished)
  config.on_event :test_run_finished, &method(:on_test_run_finished)
  config.on_event :undefined_parameter_type, &method(:on_undefined_parameter_type)

  @test_case_by_step_id = {}
  @current_test_case_started_id = nil
  @current_test_step_id = nil
end

Instance Method Details

#attach(src, media_type) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cucumber/formatter/message_builder.rb', line 45

def attach(src, media_type)
  attachment_data = {
    test_step_id: @current_test_step_id,
    test_case_started_id: @current_test_case_started_id,
    media_type: media_type
  }

  if media_type.start_with?('text/')
    attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::IDENTITY
    attachment_data[:body] = src
  else
    body = src.respond_to?(:read) ? src.read : src

    attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::BASE64
    attachment_data[:body] = Base64.strict_encode64(body)
  end

  message = Cucumber::Messages::Envelope.new(
    attachment: Cucumber::Messages::Attachment.new(**attachment_data)
  )

  output_envelope(message)
end

#output_messageObject



41
42
43
# File 'lib/cucumber/formatter/message_builder.rb', line 41

def output_message
  raise 'To be implemented'
end