Class: RSpec::Conductor::Formatters::CI

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec/conductor/formatters/ci.rb

Constant Summary collapse

DEFAULT_PRINTOUT_INTERVAL =
10

Constants included from Util::ANSI

Util::ANSI::ANSI_SEQUENCE_REGEX, Util::ANSI::COLOR_CODES, Util::ANSI::VISIBLE_CHAR_GROUP_REGEX

Instance Method Summary collapse

Methods inherited from Base

#colorize, #handle_worker_stderr, #handle_worker_stdout, #print_debug, #print_retry_message, #print_shutdown_banner, #print_slowest, #print_startup_banner, #print_summary

Methods included from Util::ANSI

clear_line, clear_line_forward, color_code, colorize, cursor_back, cursor_column, cursor_down, cursor_end_of_line, cursor_forward, cursor_up, split_visible_char_groups, tty_height, tty_width, visible_chars

Constructor Details

#initialize(printout_interval: DEFAULT_PRINTOUT_INTERVAL, **kwargs) ⇒ CI

Returns a new instance of CI.

Parameters:

  • printout_interval (Hash) (defaults to: DEFAULT_PRINTOUT_INTERVAL)

    a customizable set of options

Options Hash (printout_interval:):

  • how (Object)

    often a printout happens, in seconds



10
11
12
13
14
15
# File 'lib/rspec/conductor/formatters/ci.rb', line 10

def initialize(printout_interval: DEFAULT_PRINTOUT_INTERVAL, **kwargs)
  @printout_interval = printout_interval
  @last_printout = Time.now

  super(**kwargs)
end

Instance Method Details

#handle_worker_message(_worker_process, message, suite_run) ⇒ Object



17
18
19
20
# File 'lib/rspec/conductor/formatters/ci.rb', line 17

def handle_worker_message(_worker_process, message, suite_run)
  public_send(message[:type], message) if respond_to?(message[:type])
  print_status(suite_run) if @last_printout + @printout_interval < Time.now
end


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rspec/conductor/formatters/ci.rb', line 22

def print_status(suite_run)
  @last_printout = Time.now
  pct = suite_run.spec_file_processed_percentage

  puts "-" * tty_width
  puts "Current status [#{Time.now.strftime("%H:%M:%S")}]:"
  puts "Processed: #{suite_run.spec_files_processed} / #{suite_run.spec_files_total} (#{(pct * 100).floor}%)"
  puts "#{suite_run.examples_passed} passed, #{suite_run.examples_failed} failed, #{suite_run.examples_pending} pending"
  if suite_run.errors.any?
    puts "Failures:\n"
    suite_run.errors.each_with_index do |error, i|
      puts "  #{i + 1}) #{error[:description]}"
      puts "     #{error[:location]}"
      puts "     #{error[:message]}" if error[:message]
      if error[:backtrace]&.any?
        puts "     Backtrace:"
        error[:backtrace].each { |line| puts "       #{line}" }
      end
      puts
    end
  end
  puts "-" * tty_width
end