Class: TestBench::Output::Summary

Inherits:
Object
  • Object
show all
Includes:
Fixture::Output, Writer::Dependency
Defined in:
lib/test_bench/output/summary.rb,
lib/test_bench/output/summary/session.rb

Defined Under Namespace

Modules: Session

Instance Attribute Summary collapse

Attributes included from Writer::Dependency

#writer

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_fileObject

Returns the value of attribute current_file.



55
56
57
# File 'lib/test_bench/output/summary.rb', line 55

def current_file
  @current_file
end

#elapsed_timeObject



38
39
40
# File 'lib/test_bench/output/summary.rb', line 38

def elapsed_time
  @elapsed_time ||= 0
end

#error_countObject



33
34
35
# File 'lib/test_bench/output/summary.rb', line 33

def error_count
  @error_count ||= 0
end

#errors_by_fileObject



48
49
50
51
52
# File 'lib/test_bench/output/summary.rb', line 48

def errors_by_file
  @errors_by_file ||= Hash.new do |hash, key|
    hash[key] = []
  end
end

#failure_countObject



28
29
30
# File 'lib/test_bench/output/summary.rb', line 28

def failure_count
  @failure_count ||= 0
end

#file_countObject



8
9
10
# File 'lib/test_bench/output/summary.rb', line 8

def file_count
  @file_count ||= 0
end

#pass_countObject



18
19
20
# File 'lib/test_bench/output/summary.rb', line 18

def pass_count
  @pass_count ||= 0
end

#skip_countObject



23
24
25
# File 'lib/test_bench/output/summary.rb', line 23

def skip_count
  @skip_count ||= 0
end

#test_countObject



13
14
15
# File 'lib/test_bench/output/summary.rb', line 13

def test_count
  @test_count ||= 0
end

#timerObject



43
44
45
# File 'lib/test_bench/output/summary.rb', line 43

def timer
  @timer ||= Timer::Substitute.build
end

Class Method Details

.build(writer: nil, device: nil, styling: nil) ⇒ Object



62
63
64
65
66
# File 'lib/test_bench/output/summary.rb', line 62

def self.build(writer: nil, device: nil, styling: nil)
  instance = new
  instance.configure(writer: writer, device: device, styling: styling)
  instance
end

Instance Method Details

#configure(writer: nil, device: nil, styling: nil) ⇒ Object



57
58
59
60
# File 'lib/test_bench/output/summary.rb', line 57

def configure(writer: nil, device: nil, styling: nil)
  Writer.configure(self, writer: writer, device: device, styling: styling)
  Timer.configure(self)
end

#enter_file(file) ⇒ Object



68
69
70
71
72
# File 'lib/test_bench/output/summary.rb', line 68

def enter_file(file)
  timer.start

  self.current_file = file
end

#error(error) ⇒ Object



96
97
98
99
100
# File 'lib/test_bench/output/summary.rb', line 96

def error(error)
  errors_by_file[current_file] << error

  self.error_count += 1
end

#error_summaryObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/test_bench/output/summary.rb', line 112

def error_summary
  return if errors_by_file.empty?

  writer
    .escape_code(:bold)
    .escape_code(:red)
    .text('Error Summary:')
    .escape_code(:reset_intensity)
    .escape_code(:reset_fg)
    .newline

  errors_by_file.each do |file, errors|
    error_count = errors.count

    writer
      .text(error_count.to_s.rjust(4, ' '))
      .text(": #{file}")
      .newline

    errors.each do |error|
      writer
        .text('      ')
        .escape_code(:red)

      PrintError.error_message(error, writer: writer)

      writer.escape_code(:reset_fg)
    end
  end

  writer.newline
end

#exit_file(_, _) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/test_bench/output/summary.rb', line 74

def exit_file(_, _)
  elapsed_time = timer.stop

  self.elapsed_time += elapsed_time

  self.file_count += 1
end

#finish(_) ⇒ Object



102
103
104
105
106
# File 'lib/test_bench/output/summary.rb', line 102

def finish(_)
  error_summary

  session_summary
end

#finish_test(_, result) ⇒ Object



82
83
84
85
86
87
88
89
90
# File 'lib/test_bench/output/summary.rb', line 82

def finish_test(_, result)
  self.test_count += 1

  if result
    self.pass_count += 1
  else
    self.failure_count += 1
  end
end

#session_summaryObject



108
109
110
# File 'lib/test_bench/output/summary.rb', line 108

def session_summary
  Session.(file_count: file_count, test_count: test_count, pass_count: pass_count, skip_count: skip_count, failure_count: failure_count, error_count: error_count, elapsed_time: elapsed_time, writer: writer)
end

#skip_test(_) ⇒ Object



92
93
94
# File 'lib/test_bench/output/summary.rb', line 92

def skip_test(_)
  self.skip_count += 1
end