class Strut::ReportPrettyFormatter
Public Class Methods
new(lines)
click to toggle source
# File lib/strut/report_pretty_formatter.rb, line 8 def initialize(lines) @lines = lines end
Public Instance Methods
format(report)
click to toggle source
# 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)
click to toggle source
# 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.message) when ANNOTATION_FAIL print_fail_line(line, annotation.message) else print_ok_line(line) end end
print_error_line(line, line_fg, line_bg, message, message_fg, message_bg)
click to toggle source
# File lib/strut/report_pretty_formatter.rb, line 74 def print_error_line(line, line_fg, line_bg, message, message_fg, message_bg) print_line(line, line_fg, line_bg) print_line(message, message_fg, message_bg) end
print_errors(report)
click to toggle source
# 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)
click to toggle source
# File lib/strut/report_pretty_formatter.rb, line 62 def print_exception_line(line, message) print_error_line(line, :black, :on_yellow, message, :yellow, :on_black) end
print_fail_line(line, message)
click to toggle source
# File lib/strut/report_pretty_formatter.rb, line 66 def print_fail_line(line, message) print_error_line(line, :white, :on_red, message, :red, :on_white) end
print_line(line, foreground, background)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/strut/report_pretty_formatter.rb, line 44 def print_unannotated_line(line) puts line end