Class: ReportPortal::Cucumber::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/report_portal/cucumber/formatter.rb

Direct Known Subclasses

ParallelFormatter

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Formatter

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 Formatter.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/report_portal/cucumber/formatter.rb', line 27

def initialize(config)
  ENV['REPORT_PORTAL_USED'] = 'true'

  @queue = Queue.new
  @thread = Thread.new do
    @report = ReportPortal::Cucumber::Report.new
    loop do
      method_arr = @queue.pop
      @report.public_send(*method_arr)
    end
  end
  @thread.abort_on_exception = true

  @io = config.out_stream

  [:test_case_started, :test_case_finished, :test_step_started, :test_step_finished].each do |event_name|
    config.on_event event_name do |event|
      @queue.push([event_name, event, ReportPortal.now])
    end
  end
  config.on_event :test_run_finished, &method(:on_test_run_finished)
end

Instance Method Details

#embed(*args) ⇒ Object



56
57
58
# File 'lib/report_portal/cucumber/formatter.rb', line 56

def embed(*args)
  @queue.push([:embed, *args, ReportPortal.now])
end

#on_test_run_finished(_event) ⇒ Object



60
61
62
63
64
# File 'lib/report_portal/cucumber/formatter.rb', line 60

def on_test_run_finished(_event)
  @queue.push([:done, ReportPortal.now])
  sleep 0.03 while !@queue.empty? || @queue.num_waiting == 0 # TODO: how to interrupt launch if the user aborted execution

  @thread.kill
end

#puts(message) ⇒ Object



50
51
52
53
54
# File 'lib/report_portal/cucumber/formatter.rb', line 50

def puts(message)
  @queue.push([:puts, message, ReportPortal.now])
  @io.puts(message)
  @io.flush
end