Class: Doctrine::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/doctrine/reporter.rb

Overview

public

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, tty: $stdout.tty?) ⇒ Reporter

Returns a new instance of Reporter.


9
10
11
12
13
14
# File 'lib/doctrine/reporter.rb', line 9

def initialize(output: $stdout, tty: $stdout.tty?)
  @output = output
  @tty = tty
  @started = current_time
  @pastel = Pastel.new
end

Instance Method Details

#finished(tenet) ⇒ Object


19
20
# File 'lib/doctrine/reporter.rb', line 19

def finished(tenet)
end

#starting(tenet) ⇒ Object


16
17
# File 'lib/doctrine/reporter.rb', line 16

def starting(tenet)
end

#summarize(tenets) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
# File 'lib/doctrine/reporter.rb', line 22

def summarize(tenets)
  elapsed_ms = ((current_time - @started) * 1_000)

  if elapsed_ms > 1_000
    elapsed = elapsed_ms / 1_000
    elapsed_units = "s"
  else
    elapsed = elapsed_ms
    elapsed_units = "ms"
  end

  tenet_text = if tenets.count == 1
    "tenet"
  else
    "tenets"
  end

  failures = []
  tenets.each do |tenet|
    if tenet.errored?
      failures << tenet
      @output << decorate("x", color: :red)
    else
      @output << decorate(".", color: :green)
    end
  end

  summary_text = "Tested #{tenets.count} #{tenet_text} in #{elapsed.round(2)}#{elapsed_units}"

  if failures.any?
    failure_text = if failures.count == 1
      "failure"
    else
      "failures"
    end

    failures.each do |failure|
      @output << "\n"
      @output << "\n"
      @output << decorate(failure.error.to_s, color: :red)
      failure.error.backtrace.each do |line|
        @output << "\n"
        @output << decorate(line, color: :red)
      end
    end

    @output << "\n"
    @output << "\n"
    @output << summary_text
    @output << decorate(" (#{failures.count} #{failure_text})", color: :red)
  else
    @output << "\n"
    @output << "\n"
    @output << summary_text
    @output << decorate(" (good to go)", color: :green)
  end

  @output << "\n"
end