Class: TestBench::Run::Summary

Inherits:
Object
  • Object
show all
Includes:
ImportConstants, Telemetry::Sink::Handler
Defined in:
lib/test_bench/run/summary.rb,
lib/test_bench/run/summary/substitute.rb

Direct Known Subclasses

Substitute::Summary

Defined Under Namespace

Modules: Substitute Classes: FileInfo, FileStack, FileTotals

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_totalsObject



19
20
21
# File 'lib/test_bench/run/summary.rb', line 19

def file_totals
  @file_totals ||= FileTotals.initial
end

#filesObject



24
25
26
# File 'lib/test_bench/run/summary.rb', line 24

def files
  @files ||= {}
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#statusObject



14
15
16
# File 'lib/test_bench/run/summary.rb', line 14

def status
  @status ||= Session::Status.initial
end

#writerObject



9
10
11
# File 'lib/test_bench/run/summary.rb', line 9

def writer
  @writer ||= Output::Writer::Substitute.build
end

Class Method Details

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



35
36
37
38
39
40
41
42
43
# File 'lib/test_bench/run/summary.rb', line 35

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

  instance.start_time = ::Time.now

  Output::Writer.configure(instance, styling:, device:)

  instance
end

.configure(receiver, styling: nil, device: nil, attr_name: nil) ⇒ Object



45
46
47
48
49
50
# File 'lib/test_bench/run/summary.rb', line 45

def self.configure(receiver, styling: nil, device: nil, attr_name: nil)
  attr_name ||= :summary

  instance = build(styling:, device:)
  receiver.public_send(:"#{attr_name}=", instance)
end

Instance Method Details

#add_file(file_info) ⇒ Object



313
314
315
316
317
# File 'lib/test_bench/run/summary.rb', line 313

def add_file(file_info)
  file_path = file_info.file_path

  files[file_path] = file_info
end

#current_fileObject



319
320
321
322
323
# File 'lib/test_bench/run/summary.rb', line 319

def current_file
  current_file_path = file_stack.current_file

  files[current_file_path]
end

#current_file?Boolean

Returns:

  • (Boolean)


325
326
327
# File 'lib/test_bench/run/summary.rb', line 325

def current_file?
  file_stack.current_file?
end

#file_stackObject



29
30
31
# File 'lib/test_bench/run/summary.rb', line 29

def file_stack
  @file_stack ||= FileStack.new
end


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/test_bench/run/summary.rb', line 124

def print(finish_time=nil)
  finish_time ||= ::Time.now

  if not start_time.nil?
    elapsed_time = finish_time - start_time
  else
    elapsed_time = 0.0
  end

  tests_per_second = status.test_sequence / elapsed_time

  if files.any?
    none_failed = files.each_value.none?(&:failed?)

    if writer.styling?
      writer.
        style(:bold, :underline)

      if not none_failed
        writer.style(:red)
      end
    end

    writer.puts("File Summary")

    if not writer.styling?
      writer.puts("- - -")
    end

    files.each_value do |file_info|
      if file_info.failed?
        writer.style(:red)
      end

      writer.
        style(:faint).
        print('-').
        style(:reset_intensity).
        print(' ').
        style(:bold).
        print(file_info.file_path).
        style(:reset_intensity).
        print(': ')

      separator = false

      if file_info.not_found?
        writer.
          puts('file not found').
          puts

        next
      end

      if not file_info.tests?
        if not file_info.failed?
          writer.style(:faint, :italic)
        end

        writer.print('no tests')

        if not file_info.failed?
          writer.style(:reset_italic, :reset_intensity)
        end

        separator = true
      end

      if file_info.failures?
        writer.print(', ') if separator
        writer.print(file_info.failures)

        separator = true
      end

      if file_info.skipped?
        writer.print(', ') if separator

        if not file_info.failed?
          writer.style(:bold, :yellow)
        end

        writer.print(file_info.skipped)

        separator = true
      end

      if file_info.errors?
        writer.print(', ') if separator

        writer.print(file_info.errors)

        separator = true
      end

      writer.puts

      writer.increase_indentation

      file_info.aborted_events.each_with_index do |aborted, index|
        message = aborted.message
        location = aborted.location

        if not index.zero?
          writer.puts
        end

        writer.
          indent.
          style(:red).
          puts(message)

        writer.
          indent.
          style(:red).
          puts(location)
      end

      writer.decrease_indentation

      writer.puts
    end
  end

  writer.
    print("Attempted %s: %s, " % [file_totals.attempted, file_totals.completed])

  if file_totals.aborted?
    writer.style(:bold, :red)
  end

  writer.print("%s" % file_totals.aborted)

  if file_totals.aborted?
    writer.style(:reset_fg, :reset_intensity)
  end

  writer.print(', ')

  if file_totals.not_found?
    writer.style(:red)
  end

  writer.puts("%s" % file_totals.not_found)

  writer.
    puts("%i test#{'s' if status.test_sequence != 1} in %0.2f seconds (%0.2f tests/sec)" % [status.test_sequence, elapsed_time, tests_per_second])

  if status.test_sequence.zero?
    writer.
      style(:faint, :italic).
      print('0 passed').
      style(:reset_italic, :reset_intensity)

  else
    passed_tests = status.test_sequence - status.failure_sequence

    writer.
      style(:green).
      print("%i passed" % passed_tests).
      style(:reset_fg)
  end

  writer.print(', ')

  if status.failure_sequence.zero?
    writer.print('0 failed')
  else
    writer.
      style(:bold, :red).
      print("%i failed" % status.failure_sequence).
      style(:reset_fg, :reset_intensity)
  end

  writer.print(', ')

  if status.skip_sequence.zero?
    writer.print('0 skipped')
  else
    writer.
      style(:yellow).
      print("%i+ skipped" % status.skip_sequence)
  end

  2.times do
    writer.puts
  end
end