Class: Rpruby::Cucumber::MessagesReport Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rpruby/cucumber/messagereport.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(ast_lookup) ⇒ MessagesReport

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MessagesReport.



20
21
22
23
24
25
26
# File 'lib/rpruby/cucumber/messagereport.rb', line 20

def initialize(ast_lookup)
  @last_used_time = 0
  @root_node = Tree::TreeNode.new('')
  @parent_item_node = @root_node
  @ast_lookup = ast_lookup
  start_launch
end

Instance Method Details

#attach_to_launch?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


16
17
18
# File 'lib/rpruby/cucumber/messagereport.rb', line 16

def attach_to_launch?
  Rpruby::Settings.instance.formatter_modes.include?('attach_to_launch')
end

#embed(path_or_src, mime_type, label, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



136
137
138
# File 'lib/rpruby/cucumber/messagereport.rb', line 136

def embed(path_or_src, mime_type, label, desired_time = Rpruby.now)
  Rpruby.send_file(:info, path_or_src, label, time_to_send(desired_time), mime_type)
end

#parallel?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


12
13
14
# File 'lib/rpruby/cucumber/messagereport.rb', line 12

def parallel?
  false
end

#puts(message, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/rpruby/cucumber/messagereport.rb', line 132

def puts(message, desired_time = Rpruby.now)
  Rpruby.send_log(:info, message, time_to_send(desired_time))
end

#start_launch(desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rpruby/cucumber/messagereport.rb', line 28

def start_launch(desired_time = Rpruby.now)
  if attach_to_launch?
    Rpruby.launch_id =
      if Rpruby::Settings.instance.launch_id
        Rpruby::Settings.instance.launch_id
      else
        file_path = Rpruby::Settings.instance.file_with_launch_id || (Pathname(Dir.tmpdir) + 'rp_launch_id.tmp')
        File.read(file_path)
      end
    $stdout.puts "Attaching to launch #{Rpruby.launch_id}"
  else
    description = Rpruby::Settings.instance.description
    description ||= ARGV.map { |arg| arg.gsub(/rp_uuid=.+/, 'rp_uuid=[FILTERED]') }.join(' ')
    Rpruby.start_launch(description, time_to_send(desired_time))
  end
end

#test_case_finished(event, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rpruby/cucumber/messagereport.rb', line 66

def test_case_finished(event, desired_time = Rpruby.now)
  result = event.result
  status = result.to_sym
  issue = nil
  if %i[undefined pending].include?(status)
    status = :failed
    issue = result.message
  end
  Rpruby.finish_item(Rpruby.current_scenario, status, time_to_send(desired_time), issue)
  Rpruby.current_scenario = nil
end

#test_case_started(event, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: time should be a required argument



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rpruby/cucumber/messagereport.rb', line 46

def test_case_started(event, desired_time = Rpruby.now)
  test_case = event.test_case
  test_source = @ast_lookup.scenario_source(test_case).scenario
  gherkin_source = @ast_lookup.gherkin_document(test_case.location.file)
  if report_hierarchy? && !same_feature_as_previous_test_case?(gherkin_source)
    end_feature(desired_time) unless @parent_item_node.is_root?
    start_feature_with_parentage(gherkin_source, desired_time)
  end

  name = "#{test_source.keyword}: #{test_source.name}"
  description = test_case.location.to_s
  tags = test_case.tags.map(&:name)
  type = :STEP

  Rpruby.current_scenario = Rpruby::TestItem.new(name: name, type: type, id: nil, start_time: time_to_send(desired_time), description: description, closed: false, tags: tags)
  scenario_node = Tree::TreeNode.new(SecureRandom.hex, Rpruby.current_scenario)
  @parent_item_node << scenario_node
  Rpruby.current_scenario.id = Rpruby.start_item(scenario_node)
end

#test_run_finished(_event, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



122
123
124
125
126
127
128
129
130
# File 'lib/rpruby/cucumber/messagereport.rb', line 122

def test_run_finished(_event, desired_time = Rpruby.now)
  end_feature(desired_time) unless @parent_item_node.is_root?

  unless attach_to_launch?
    close_all_children_of(@root_node) # Folder items are closed here as they can't be closed after finishing a feature
    time_to_send = time_to_send(desired_time)
    Rpruby.finish_launch(time_to_send)
  end
end

#test_step_finished(event, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/rpruby/cucumber/messagereport.rb', line 92

def test_step_finished(event, desired_time = Rpruby.now)
  test_step = event.test_step
  result = event.result
  status = result.to_sym

  if %i[failed pending undefined].include?(status)
    exception_info = if %i[failed pending].include?(status)
                       ex = result.exception
                       format("%s: %s\n  %s", ex.class.name, ex.message, ex.backtrace.join("\n  "))
                     else
                       format("Undefined step: %s:\n%s", test_step.text, test_step.source.last.backtrace_line)
                     end
    Rpruby.send_log(:error, exception_info, time_to_send(desired_time))
  end

  if status != :passed
    log_level = status == :skipped ? :warn : :error
    step_type = if step?(test_step)
                  'Step'
                else
                  # TODO: Find out what this looks like in Cucumber3, to try and track down
                  # how we ought to behave
                  hook_class_name = test_step.text
                  location = test_step.location.to_s
                  "#{hook_class_name} at `#{location}`"
                end
    Rpruby.send_log(log_level, "#{step_type} #{status}", time_to_send(desired_time))
  end
end

#test_step_started(event, desired_time = Rpruby.now) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rpruby/cucumber/messagereport.rb', line 78

def test_step_started(event, desired_time = Rpruby.now)
  test_step = event.test_step
  if step?(test_step) # `after_test_step` is also invoked for hooks
    step_source = step_source = @ast_lookup.step_source(test_step).step
    message = "-- #{step_source.keyword}#{step_source.text} --"
    if test_step.multiline_arg.doc_string?
      message << %(\n"""\n#{test_step.multiline_arg.content}\n""")
    elsif test_step.multiline_arg.data_table?
      message << test_step.multiline_arg.raw.reduce("\n") { |acc, row| acc << "| #{row.join(' | ')} |\n" }
    end
    Rpruby.send_log(:trace, message, time_to_send(desired_time))
  end
end