Class: LesliTesting::Reporters::CliReporter

Inherits:
Minitest::StatisticsReporter
  • Object
show all
Defined in:
lib/lesli_testing/minitest/cli_reporter.rb

Instance Method Summary collapse

Instance Method Details

#record(test) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/lesli_testing/minitest/cli_reporter.rb', line 50

def record(test)
    super

    # Only print the line if the configuration allows it
    return if ENV["QUIET"]

    # Map result codes to styles
    status_map = { 
        "." => [:green, "PASS"], 
        "S" => [:yellow, "SKIP"], 
        "E" => [:red, "ERROR"], 
        "F" => [:red, "FAIL"]
    }
    color, label = status_map[test.result_code] || [:gray, "????"]

    # Determine assertion health
    assert_color = case test.assertions
        when 0..1 then :red
        when 2..4 then :yellow
        else :green
    end

    parts = [
        Termline::Style.colorize("[#{Time.now.strftime('%H:%M:%S')}]", :gray),
        Termline::Style.colorize(label, color),
        "::",
        Termline::Style.colorize(test.klass, :blue),
        "->",
        Termline::Style.colorize(test.name, :skyblue),
        Termline::Style.colorize("(#{test.assertions} asserts)", assert_color)
    ]

    # Add execution time per test
    parts << Termline::Style.colorize("(%.2fs)" % test.time, :red) if test.time > 1

    puts(parts.join(" "))
end

#reportObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/lesli_testing/minitest/cli_reporter.rb', line 88

def report
    super

    total_tests = count.to_i
    total_failures = failures.to_i
    total_errors = errors.to_i
    total_skips = skips.to_i
    total_assertions = assertions.to_i
    duration = total_time.to_f

    passed = total_tests - total_failures - total_errors - total_skips
    success_rate = total_tests.zero? ? 0 : ((passed.to_f / total_tests) * 100).round(1)
    status = (total_failures.zero? && total_errors.zero?) ? "PASS" : "FAIL"

    Termline.br 2

    status_color = :blue
    status_color = :red if status == 'FAIL'

    failures_color = :blue
    failures_color = :red if total_failures > 0

    puts(Termline::Msg.builder(status,                   tag:'STATUS . . . . . . . :', color: status_color, timestamp:nil))
    puts(Termline::Msg.builder(total_tests,              tag:'TESTS. . . . . . . . :', color: :blue, timestamp:nil))
    puts(Termline::Msg.builder(passed,                   tag:'PASSED . . . . . . . :', color: :blue, timestamp:nil))
    puts(Termline::Msg.builder(total_failures,           tag:'FAILURES . . . . . . :', color: failures_color, timestamp:nil))
    puts(Termline::Msg.builder(total_errors,             tag:'ERRORS . . . . . . . :', color: :blue, timestamp:nil))
    puts(Termline::Msg.builder(total_skips,              tag:'SKIPPED. . . . . . . :', color: :blue, timestamp:nil))
    puts(Termline::Msg.builder(total_assertions,         tag:'ASSERTIONS . . . . . :', color: :blue, timestamp:nil))
    puts(Termline::Msg.builder("#{success_rate}%",       tag:'SUCCESS RATE . . . . :', color: failures_color, timestamp:nil))
    puts(Termline::Msg.builder(format("%.2fs", duration),tag:'TIME . . . . . . . . :', color: :blue, timestamp:nil))

    Termline.br 2

    if status == "PASS"
        Termline.success("Test suite passed")
    else
        Termline.danger("Test suite failed", tag:'FAILURE')
    end

    Termline.br 2

    print_failure_details if total_failures.positive? || total_errors.positive?

end

#startObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/lesli_testing/minitest/cli_reporter.rb', line 36

def start
    super

    Termline.br

    Termline.m(
        Termline::Style.colorize("Running Lesli tests...", :blue),
        Termline::Style.colorize("-> For a better result run test over a clean database", :blue),
        Termline::Style.colorize("-> You can use: rake dev:db:reset", :blue)
    )

    Termline.br 2
end