Class: Strut::ReportPrettyFormatter
- Inherits:
-
Object
- Object
- Strut::ReportPrettyFormatter
- Defined in:
- lib/strut/report_pretty_formatter.rb
Instance Method Summary collapse
- #format(report) ⇒ Object
-
#initialize(lines) ⇒ ReportPrettyFormatter
constructor
A new instance of ReportPrettyFormatter.
- #print_annotated_line(annotations, line) ⇒ Object
- #print_error_line(line, line_fg, line_bg, message, message_fg, message_bg) ⇒ Object
- #print_errors(report) ⇒ Object
- #print_exception_line(line, message) ⇒ Object
- #print_fail_line(line, message) ⇒ Object
- #print_line(line, foreground, background) ⇒ Object
- #print_line_with_annotations(line, annotations) ⇒ Object
- #print_ok_line(line) ⇒ Object
- #print_report_to_stdout(report) ⇒ Object
- #print_unannotated_line(line) ⇒ Object
Constructor Details
#initialize(lines) ⇒ ReportPrettyFormatter
Returns a new instance of ReportPrettyFormatter.
8 9 10 |
# File 'lib/strut/report_pretty_formatter.rb', line 8 def initialize(lines) @lines = lines end |
Instance Method Details
#format(report) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/strut/report_pretty_formatter.rb', line 12 def format(report) begin out = StringIO.new $stdout = out print_report_to_stdout(report) ensure $stdout = STDOUT end out.string end |
#print_annotated_line(annotations, line) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/strut/report_pretty_formatter.rb', line 48 def print_annotated_line(annotations, line) # TODO: print all annotations, not just the first annotation = annotations.first case annotation.type when ANNOTATION_EXCEPTION print_exception_line(line, annotation.) when ANNOTATION_FAIL print_fail_line(line, annotation.) else print_ok_line(line) end end |
#print_error_line(line, line_fg, line_bg, message, message_fg, message_bg) ⇒ Object
74 75 76 77 |
# File 'lib/strut/report_pretty_formatter.rb', line 74 def print_error_line(line, line_fg, line_bg, , , ) print_line(line, line_fg, line_bg) print_line(, , ) end |
#print_errors(report) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/strut/report_pretty_formatter.rb', line 83 def print_errors(report) return if report.errors.empty? report.errors.each do |error| print red { error }, "\n" end puts end |
#print_exception_line(line, message) ⇒ Object
62 63 64 |
# File 'lib/strut/report_pretty_formatter.rb', line 62 def print_exception_line(line, ) print_error_line(line, :black, :on_yellow, , :yellow, :on_black) end |
#print_fail_line(line, message) ⇒ Object
66 67 68 |
# File 'lib/strut/report_pretty_formatter.rb', line 66 def print_fail_line(line, ) print_error_line(line, :white, :on_red, , :red, :on_white) end |
#print_line(line, foreground, background) ⇒ Object
79 80 81 |
# File 'lib/strut/report_pretty_formatter.rb', line 79 def print_line(line, foreground, background) puts line.send(foreground).send(background) end |
#print_line_with_annotations(line, annotations) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/strut/report_pretty_formatter.rb', line 36 def print_line_with_annotations(line, annotations) if annotations.empty? print_unannotated_line(line) elsif print_annotated_line(annotations, line) end end |
#print_ok_line(line) ⇒ Object
70 71 72 |
# File 'lib/strut/report_pretty_formatter.rb', line 70 def print_ok_line(line) print_line(line, :black, :on_green) end |
#print_report_to_stdout(report) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/strut/report_pretty_formatter.rb', line 23 def print_report_to_stdout(report) @lines.each_line.each_with_index do |line, index| annotations = report.annotations_for_line(index+1) print_line_with_annotations(line.chomp, annotations) end puts print_errors(report) print "#{report.number_scenarios} scenarios (" print green { "#{report.number_passed} passed" }, ", " print red { "#{report.number_failed} failed" }, ", " print yellow { "#{report.number_skipped} skipped" }, ")" end |
#print_unannotated_line(line) ⇒ Object
44 45 46 |
# File 'lib/strut/report_pretty_formatter.rb', line 44 def print_unannotated_line(line) puts line end |