Class: Jstdutil::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/jstdutil/formatter.rb

Class Method Summary collapse

Class Method Details

.format(report, type) ⇒ Object

Process report from JsTestDriver and colorize it with beautiful colors. Returns report with encoded colors.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jstdutil/formatter.rb', line 7

def self.format(report, type)
  return "" if report.nil?

  begin
    type.wrap_report(report.split("\n").collect do |line|
      if line =~ /Passed: 0; Fails: 0; Errors:? 0/
        type::Color.yellow(line)
      elsif line =~ /Passed: \d+; Fails: (\d+); Errors:? (\d+)/
        type::Color.send($1.to_i + $2.to_i != 0 ? :red : :green, line)
      elsif line =~ /^[\.EF]+$/
        line.gsub(/\./, type::Color.green(".")).gsub(/F/, type::Color.red("F")).gsub("E", type::Color.yellow("E"))
      elsif line =~ /failed\s\(\d|\[ERROR\]/
        type::Color.red(line)
      elsif line =~ /passed\s\(\d/
        type::Color.green(line)
      elsif line =~ /error|\[WARN\]/
        type::Color.yellow(line)
      else
        line
      end
    end.join("\n"))
  rescue
    report
  end
end