Class: Moto::Reporting::TestReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/reporting/test_reporter.rb

Overview

Manages reporting test and run status’ to attached listeners

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listeners, run_params) ⇒ TestReporter

Returns a new instance of TestReporter.

Parameters:

  • listeners (Array)

    An array of strings, which represent qualified names of classes (listeners) that will be instantiated. empty array is passed then :default_listeners will be taken from config



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/reporting/test_reporter.rb', line 13

def initialize(listeners, run_params)

  if listeners.empty?
    config[:default_listeners].each do |listener_class_name|
      listeners << listener_class_name
    end
  else
    listeners.each_with_index do |listener_class_name, index|
      listeners[index] = ('Moto::Reporting::Listeners::' + listener_class_name.camelize).constantize
    end
  end

  @listeners = []
  @run_params = run_params
  listeners.each { |l| add_listener(l) }
end

Instance Attribute Details

#run_statusObject (readonly)

Returns the value of attribute run_status.



9
10
11
# File 'lib/reporting/test_reporter.rb', line 9

def run_status
  @run_status
end

Instance Method Details

#add_listener(listener) ⇒ Object

Adds a listener to the list. All listeners on the list will have events reported to them.

Parameters:

  • listener (Moto::Listener::Base)

    class to be added



33
34
35
# File 'lib/reporting/test_reporter.rb', line 33

def add_listener(listener)
  @listeners << listener.new(@run_params)
end

#report_end_runObject

Reports end of the whole run (set of tests) to attached listeners



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/reporting/test_reporter.rb', line 52

def report_end_run
  @run_status.finalize_run

  @listeners.each do |l|
    begin
      l.end_run(@run_status)
    rescue Exception => e
      puts "Listener #{l.class.name} on End run: #{e.to_s}"
    end
  end
end

#report_end_test(test_status) ⇒ Object

Reports end of a test to all attached listeners

Parameters:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/reporting/test_reporter.rb', line 79

def report_end_test(test_status)
  @run_status.add_test_status(test_status)

  @listeners.each do |l|
    begin
      l.end_test(test_status)
    rescue Exception => e
      puts "Listener #{l.class.name} on End test: #{e.to_s}"
    end
  end
end

#report_start_runObject

Reports start of the whole run (set of tests) to attached listeners



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/reporting/test_reporter.rb', line 38

def report_start_run
  @run_status = Moto::Reporting::RunStatus.new
  @run_status.initialize_run

  @listeners.each do |l|
    begin
      l.start_run
    rescue Exception => e
      puts "Listener #{l.class.name} on Start run: #{e.to_s}"
    end
  end
end

#report_start_test(test_status, test_metadata) ⇒ Object

Reports start of a test to all attached listeners

Parameters:



67
68
69
70
71
72
73
74
75
# File 'lib/reporting/test_reporter.rb', line 67

def report_start_test(test_status, )
  @listeners.each do |l|
    begin
      l.start_test(test_status, )
    rescue Exception => e
      puts "Listener #{l.class.name} on Start test: #{e.to_s}"
    end
  end
end