|
3 | 3 | require 'rspec/core' |
4 | 4 | require 'time' |
5 | 5 | require 'context_ruby' |
6 | | -require 'colorize' |
| 6 | + |
| 7 | +class String |
| 8 | + def colorize(color_code) |
| 9 | + "\e[#{color_code}m#{self}\e[0m" |
| 10 | + end |
| 11 | + |
| 12 | + def red |
| 13 | + colorize(31) |
| 14 | + end |
| 15 | + |
| 16 | + def green |
| 17 | + colorize(32) |
| 18 | + end |
| 19 | + |
| 20 | + def yellow |
| 21 | + colorize(33) |
| 22 | + end |
| 23 | +end |
7 | 24 |
|
8 | 25 | def escape(str) |
9 | 26 | str.dump[1..-2] |
@@ -47,14 +64,14 @@ def set_exception(exception) |
47 | 64 | parent_name = parent_name.empty? ? 'rspec' : parent_name |
48 | 65 | file = escape(metadata[:file_path]) |
49 | 66 | classname = file.sub(%r{\.[^/.]+\Z}, '').gsub('/', '.').gsub(/\A\.+|\.+\Z/, '') |
50 | | - puts "Test failed, checking if it can be quarantined: `#{location}`".colorize(:yellow) |
| 67 | + puts "Test failed, checking if it can be quarantined: `#{location}`".yellow |
51 | 68 | if $test_report.is_quarantined(id, name, parent_name, classname, file) |
52 | 69 | # monitor the override in the metadata |
53 | 70 | metadata[:quarantined_exception] = exception |
54 | | - puts "Test is quarantined, overriding exception: #{exception}".colorize(:green) |
| 71 | + puts "Test is quarantined, overriding exception: #{exception}".green |
55 | 72 | nil |
56 | 73 | else |
57 | | - puts 'Test is not quarantined, continuing'.colorize(:red) |
| 74 | + puts 'Test is not quarantined, continuing'.red |
58 | 75 | set_exception_core(exception) |
59 | 76 | end |
60 | 77 | end |
@@ -117,9 +134,9 @@ def example_finished(notification) |
117 | 134 | def close(_notification) |
118 | 135 | res = @testreport.publish |
119 | 136 | if res |
120 | | - puts 'Flaky tests report upload complete'.colorize(:green) |
| 137 | + puts 'Flaky tests report upload complete'.green |
121 | 138 | else |
122 | | - puts 'Failed to publish flaky tests report'.colorize(:red) |
| 139 | + puts 'Failed to publish flaky tests report'.red |
123 | 140 | end |
124 | 141 | end |
125 | 142 |
|
|
0 commit comments