Class: JmlTestRunner::Formatters::Basic
- Inherits:
-
Base
- Object
- Base
- JmlTestRunner::Formatters::Basic
show all
- Defined in:
- lib/jml_test_runner/formatters/basic.rb
Instance Attribute Summary
Attributes inherited from Base
#suites
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#dynamic_width ⇒ Object
72
73
74
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 72
def dynamic_width
@dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
end
|
#dynamic_width_stty ⇒ Object
76
77
78
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 76
def dynamic_width_stty
`stty size 2>/dev/null`.split[1].to_i
end
|
#dynamic_width_tput ⇒ Object
80
81
82
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 80
def dynamic_width_tput
`tput cols 2>/dev/null`.to_i
end
|
20
21
22
23
24
25
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 20
def format_suite_summary(suite)
puts
separator
puts suite.title.colorize(:blue).bold
puts suite.timestamp.strftime('%D -- %H:%M:%S').colorize(:yellow)
end
|
27
28
29
30
31
32
33
34
35
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 27
def format_suite_summary_summary(suite)
full = "#{suite.count} Test(s) Run".colorize(:white)
passes = "#{suite.pass_count} Pass(es)".colorize(:green)
failures = "#{suite.failure_count} Failure(s)".colorize(:red)
errors = "#{suite.error_count} Error(s)".colorize(:yellow)
puts
puts "#{full} (#{passes} #{failures} #{errors})"
puts
end
|
rubocop:disable Metrics/MethodLength
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 38
def format_suite_test_cases(suite)
table_rows = []
suite.tests.each do |test|
if test.success?
table_rows << [test.id, "\u2714".encode('utf-8').colorize(:green)]
elsif test.error?
table_rows << [test.id, "\u25C9".encode('utf-8').colorize(:yellow)]
table_rows << ['', test.message.colorize(:yellow)]
elsif test.failure?
table_rows << [test.id, "\u2718".encode('utf-8').colorize(:red)]
table_rows << ['', test.message.colorize(:red)]
else
table_rows << [test.id, 'UNKNOWN'.colorize(:red)]
table_rows << ['', test.message.colorize(:red)]
end
end
table = Terminal::Table.new(rows: table_rows)
table.style = { border_x: '', border_i: '' }
puts table
end
|
7
8
9
10
11
12
13
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 7
def print_formatted_output
@suites.each do |suite|
format_suite_summary(suite)
format_suite_test_cases(suite)
format_suite_summary_summary(suite)
end
end
|
#separator ⇒ Object
15
16
17
18
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 15
def separator
msg = '=' * term_width
puts msg.colorize(:white).bold
end
|
#term_width ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 59
def term_width
result = if ENV['COLUMNS']
ENV['COLUMNS'].to_i
else
unix? ? dynamic_width : 80
end
result < 10 ? 80 : result
end
|
#unix? ⇒ Boolean
68
69
70
|
# File 'lib/jml_test_runner/formatters/basic.rb', line 68
def unix?
RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
end
|