class Fix::Report
The class that is responsible for reporting the result of the test.
@api private
Attributes
test[R]
@!attribute [r] test
@return [Test] The results of the test.
Public Class Methods
new(test)
click to toggle source
Initialize the report class.
@param test [Test] The test.
# File lib/fix/report.rb, line 12 def initialize(test) @test = test end
Public Instance Methods
to_s()
click to toggle source
The report in plain text.
@return [String] The report in plain text.
# File lib/fix/report.rb, line 24 def to_s [maybe_thematic_break, maybe_alerts, total_time, statistics].join end
Private Instance Methods
alerts()
click to toggle source
@private
# File lib/fix/report.rb, line 41 def alerts test.results.reject { |r| r.to_sym.equal?(:success) } end
error_color()
click to toggle source
@private
# File lib/fix/report.rb, line 101 def error_color 31 end
failure_color()
click to toggle source
@private
# File lib/fix/report.rb, line 106 def failure_color 35 end
info_color()
click to toggle source
@private
# File lib/fix/report.rb, line 111 def info_color 33 end
maybe_alerts()
click to toggle source
@private
# File lib/fix/report.rb, line 46 def maybe_alerts alerts.any? ? "#{results.join("\n")}\n" : '' end
maybe_backtrace(result)
click to toggle source
@private
# File lib/fix/report.rb, line 66 def maybe_backtrace(result) result.respond_to?(:backtrace) ? " #{result.backtrace.first}\n" : '' end
maybe_results_color(string, result)
click to toggle source
@private
# File lib/fix/report.rb, line 58 def maybe_results_color(string, result) return string unless test.configuration.fetch(:color) color = send("#{result.to_sym}_color") "\e[#{color}m#{string}\e[0m" end
maybe_thematic_break()
click to toggle source
@private
# File lib/fix/report.rb, line 31 def maybe_thematic_break test.results.any? && test.configuration.fetch(:verbose) ? "\n\n" : '' end
results()
click to toggle source
@private
# File lib/fix/report.rb, line 51 def results alerts.map.with_index(1) do |r, i| maybe_results_color("#{i}. #{r.message}\n" + maybe_backtrace(r), r) end end
statistics()
click to toggle source
@private
# File lib/fix/report.rb, line 71 def statistics if test.configuration.fetch(:color) statistics_color(statistics_text, test.statistics) else statistics_text end end
statistics_color(string, stats)
click to toggle source
@private
# File lib/fix/report.rb, line 88 def statistics_color(string, stats) if stats.fetch(:total_errors).positive? "\e[#{error_color}m#{string}\e[0m" elsif stats.fetch(:total_failures).positive? "\e[#{failure_color}m#{string}\e[0m" elsif stats.fetch(:total_infos).positive? "\e[#{info_color}m#{string}\e[0m" else "\e[#{success_color}m#{string}\e[0m" end end
statistics_text()
click to toggle source
@private
# File lib/fix/report.rb, line 80 def statistics_text "#{test.statistics.fetch(:pass_percent)}% compliant - " \ "#{test.statistics.fetch(:total_infos)} infos, " \ "#{test.statistics.fetch(:total_failures)} failures, " \ "#{test.statistics.fetch(:total_errors)} errors\n" end
success_color()
click to toggle source
@private
# File lib/fix/report.rb, line 116 def success_color 32 end
total_time()
click to toggle source
@private
# File lib/fix/report.rb, line 36 def total_time "Ran #{test.results.length} tests in #{test.total_time} seconds\n" end