Class: Cucumber::Formatter::MessageBuilder

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

Direct Known Subclasses

HTML

Constant Summary

Constants included from ANSIColor

ANSIColor::ALIASES

Constants included from Term::ANSIColor

Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP

Instance Method Summary collapse

Methods included from Console

#collect_snippet_data, #collect_undefined_parameter_type_names, #do_print_passing_wip, #do_print_profile_information, #do_print_snippets, #do_print_undefined_parameter_type_snippet, #exception_message_string, #format_step, #format_string, #indent, #linebreaks, #print_element_messages, #print_elements, #print_exception, #print_passing_wip, #print_profile_information, #print_snippets, #print_statistics

Methods included from ANSIColor

apply_custom_colors, #cukes, #green_cukes, #red_cukes, #yellow_cukes

Methods included from Term::ANSIColor

#attributes, included, #uncolored

Methods included from Duration

#format_duration

Methods included from Io

ensure_dir, ensure_file, ensure_io, included, io?, url?

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
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cucumber/formatter/message_builder.rb', line 16

def initialize(config)
  @config = config
  @ast_lookup = AstLookup.new(config)
  @repository = Cucumber::Repository.new

  @test_run_started_id = config.test_run_started_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 = {}
  @step_definition_ids_by_test_step_id = {}
  @step_match_arguments_by_test_step_id = {}

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

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

  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 :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)

  config.on_event :test_run_started, &method(:on_test_run_started)
  config.on_event :test_run_finished, &method(:on_test_run_finished)

  config.on_event :test_step_created, &method(:on_test_step_created)
  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 :envelope, &method(:on_envelope)
end

Instance Method Details

#attach(src, media_type, filename, streamed_file) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/cucumber/formatter/message_builder.rb', line 58

def attach(src, media_type, filename, streamed_file)
  attachment_data =
    if @current_test_run_hook_started_id.nil?
      {
        test_step_id: @current_test_step_id,
        test_case_started_id: @current_test_case_started_id,
        media_type: media_type,
        file_name: filename,
        timestamp: time_to_timestamp(Time.now)
      }
    else
      {
        test_run_hook_started_id: @current_test_run_hook_started_id,
        media_type: media_type,
        file_name: filename,
        timestamp: time_to_timestamp(Time.now)
      }
    end

  if streamed_file
    attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::BASE64
    attachment_data[:body] = Base64.strict_encode64(src)
  else
    attachment_data[:content_encoding] = Cucumber::Messages::AttachmentContentEncoding::IDENTITY
    attachment_data[:body] = src.is_a?(Hash) ? src.to_json : src
  end

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

#on_envelope(event) ⇒ Object



54
55
56
# File 'lib/cucumber/formatter/message_builder.rb', line 54

def on_envelope(event)
  @current_test_run_hook_started_id = event.envelope.test_run_hook_started.id if event.envelope.test_run_hook_started
end