Class: RSpec::Conductor::Formatters::Base
- Inherits:
-
Object
- Object
- RSpec::Conductor::Formatters::Base
show all
- Includes:
- Util::ANSI
- Defined in:
- lib/rspec/conductor/formatters/base.rb
Constant Summary
Constants included
from Util::ANSI
Util::ANSI::ANSI_SEQUENCE_REGEX, Util::ANSI::COLOR_CODES, Util::ANSI::VISIBLE_CHAR_GROUP_REGEX
Instance Method Summary
collapse
-
#colorize(string, colors, **kwargs) ⇒ Object
-
#handle_worker_message(_worker_process, _message, _suite_run) ⇒ Object
-
#handle_worker_stderr(worker_number, string) ⇒ Object
-
#handle_worker_stdout(worker_number, string) ⇒ Object
-
#initialize(**_kwargs) ⇒ Base
constructor
-
#print_debug(string) ⇒ Object
-
#print_retry_message(message) ⇒ Object
-
#print_shutdown_banner ⇒ Object
-
#print_slowest(suite_run, n) ⇒ Object
-
#print_startup_banner(worker_count:, seed:, spec_files_count:) ⇒ Object
-
#print_summary(suite_run, seed:, success:) ⇒ Object
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(**_kwargs) ⇒ Base
Returns a new instance of Base.
9
10
|
# File 'lib/rspec/conductor/formatters/base.rb', line 9
def initialize(**_kwargs)
end
|
Instance Method Details
#colorize(string, colors, **kwargs) ⇒ Object
85
86
87
|
# File 'lib/rspec/conductor/formatters/base.rb', line 85
def colorize(string, colors, **kwargs)
$stdout.tty? ? super(string, colors, **kwargs) : string
end
|
#handle_worker_message(_worker_process, _message, _suite_run) ⇒ Object
12
13
|
# File 'lib/rspec/conductor/formatters/base.rb', line 12
def handle_worker_message(_worker_process, _message, _suite_run)
end
|
#handle_worker_stderr(worker_number, string) ⇒ Object
63
64
65
|
# File 'lib/rspec/conductor/formatters/base.rb', line 63
def handle_worker_stderr(worker_number, string)
$stderr.puts "[worker #{worker_number}] #{string}"
end
|
#handle_worker_stdout(worker_number, string) ⇒ Object
59
60
61
|
# File 'lib/rspec/conductor/formatters/base.rb', line 59
def handle_worker_stdout(worker_number, string)
puts "[worker #{worker_number}] #{string}"
end
|
#print_debug(string) ⇒ Object
67
68
69
|
# File 'lib/rspec/conductor/formatters/base.rb', line 67
def print_debug(string)
$stderr.puts string
end
|
#print_retry_message(message) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/rspec/conductor/formatters/base.rb', line 71
def print_retry_message(message)
puts <<~EOM
\nRetried: #{message[:description]}
#{message[:location]}
#{message[:exception_class]}: #{message[:message]}
Backtrace:
#{message[:backtrace].map { |line| " #{line}" }.join("\n")}
EOM
end
|
#print_shutdown_banner ⇒ Object
81
82
83
|
# File 'lib/rspec/conductor/formatters/base.rb', line 81
def print_shutdown_banner
puts "Shutting down... (press ctrl-c again to force quit)"
end
|
#print_slowest(suite_run, n) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/rspec/conductor/formatters/base.rb', line 51
def print_slowest(suite_run, n)
puts "\n\n"
puts "Slowest #{n} specs:"
suite_run.example_stats.sort_by { |e| -e[:run_time] }.take(n).each_with_index do |e, i|
puts "%3d. (%8.2fms) %s @ %s" % [i + 1, e[:run_time] * 1000, colorize(e[:description], :dim), colorize(e[:location], :cyan)]
end
end
|
#print_startup_banner(worker_count:, seed:, spec_files_count:) ⇒ Object
15
16
17
18
|
# File 'lib/rspec/conductor/formatters/base.rb', line 15
def print_startup_banner(worker_count:, seed:, spec_files_count:)
puts "RSpec Conductor starting with #{worker_count} workers (seed: #{seed})"
puts "Running #{spec_files_count} spec files\n\n"
end
|
#print_summary(suite_run, seed:, success:) ⇒ Object
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
|
# File 'lib/rspec/conductor/formatters/base.rb', line 20
def print_summary(suite_run, seed:, success:)
puts "\n\n"
puts "Randomized with seed #{seed}"
puts "#{colorize("#{suite_run.examples_passed} passed", :green)}, #{colorize("#{suite_run.examples_failed} failed", :red)}, #{colorize("#{suite_run.examples_pending} pending", :yellow)}"
puts colorize("Worker crashes: #{suite_run.worker_crashes}", :red) if suite_run.worker_crashes.positive?
if suite_run.errors.any?
puts "\nFailures:\n\n"
suite_run.errors.each_with_index do |error, i|
puts " #{i + 1}) #{error[:description]}"
puts colorize(" #{error[:message]}", :red) if error[:message]
puts colorize(" #{error[:location]}", :cyan)
if error[:backtrace]&.any?
puts " Backtrace:"
error[:backtrace].each { |line| puts " #{line}" }
end
puts
end
end
puts "Specs took: #{suite_run.specs_runtime.round(2)}s"
puts "Total runtime: #{suite_run.total_runtime.round(2)}s"
puts "Suite: #{success ? colorize("PASSED", :green) : colorize("FAILED", :red)}"
if suite_run.errors.any?
puts ""
puts "To rerun failed examples:"
puts " rspec #{suite_run.errors.map { |e| e[:location] }.join(" ")}"
end
end
|