Class: TestBench::Output

Inherits:
Object
  • Object
show all
Includes:
Session::Handler
Defined in:
lib/test_bench/output/digest.rb,
lib/test_bench/output/output.rb,
lib/test_bench/output/writer.rb,
lib/test_bench/output/device/null.rb,
lib/test_bench/output/writer/style.rb,
lib/test_bench/output/controls/data.rb,
lib/test_bench/output/controls/text.rb,
lib/test_bench/output/writer/buffer.rb,
lib/test_bench/output/controls/style.rb,
lib/test_bench/output/controls/detail.rb,
lib/test_bench/output/controls/device.rb,
lib/test_bench/output/controls/events.rb,
lib/test_bench/output/controls/output.rb,
lib/test_bench/output/controls/random.rb,
lib/test_bench/output/controls/result.rb,
lib/test_bench/output/writer/defaults.rb,
lib/test_bench/output/controls/styling.rb,
lib/test_bench/output/device/substitute.rb,
lib/test_bench/output/writer/substitute.rb,
lib/test_bench/output/writer/buffer/console.rb

Defined Under Namespace

Modules: Controls, Detail, Device, Mode Classes: Digest, Writer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#branch_countObject



35
36
37
# File 'lib/test_bench/output/output.rb', line 35

def branch_count
  @branch_count ||= 0
end

#detail_policyObject Also known as: detail



40
41
42
# File 'lib/test_bench/output/output.rb', line 40

def detail_policy
  @detail_policy ||= Detail.default
end

#failing_writerObject



15
16
17
# File 'lib/test_bench/output/output.rb', line 15

def failing_writer
  @failing_writer ||= Writer::Substitute.build
end

#failuresObject



20
21
22
# File 'lib/test_bench/output/output.rb', line 20

def failures
  @failures ||= []
end

#modeObject



25
26
27
# File 'lib/test_bench/output/output.rb', line 25

def mode
  @mode ||= Mode.initial
end

#passing_writerObject



10
11
12
# File 'lib/test_bench/output/output.rb', line 10

def passing_writer
  @passing_writer ||= Writer::Substitute.build
end

#pending_writerObject



5
6
7
# File 'lib/test_bench/output/output.rb', line 5

def pending_writer
  @pending_writer ||= Writer::Substitute.build
end

Class Method Details

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



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/test_bench/output/output.rb', line 46

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

  Writer.configure(instance, device:, styling:, attr_name: :pending_writer)

  if not detail.nil?
    instance.detail_policy = detail
  end

  instance
end

.register(telemetry, **arguments) ⇒ Object



58
59
60
61
62
63
# File 'lib/test_bench/output/output.rb', line 58

def self.register(telemetry, **arguments)
  instance = build(**arguments)

  telemetry.register(instance)
  instance
end

Instance Method Details

#branchObject



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/test_bench/output/output.rb', line 230

def branch
  if branch_count.zero?
    self.mode = Mode.pending

    pending_writer.sync = false

    parent_writer = pending_writer
  else
    parent_writer = passing_writer
  end

  self.branch_count += 1

  self.passing_writer, self.failing_writer = parent_writer.branch
end

#branched?Boolean

Returns:

  • (Boolean)


267
268
269
# File 'lib/test_bench/output/output.rb', line 267

def branched?
  branch_count > 0
end

#comment(text, quote, heading) ⇒ Object



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
# File 'lib/test_bench/output/output.rb', line 190

def comment(text, quote, heading)
  if not heading.nil?
    writer.style(:bold, :underline).puts(heading)
  end

  if text.empty?
    writer.
      indent.
      style(:faint, :italic).
      puts('(empty)')
    return
  end

  if not quote
    writer.puts(text)
  else
    text.each_line do |line|
      line.chomp!

      writer.
        indent.
        style(:faint).
        print('> ').
        style(:reset_intensity).
        puts(line)
    end
  end
end

#current_writerObject Also known as: writer



219
220
221
222
223
224
225
226
227
# File 'lib/test_bench/output/output.rb', line 219

def current_writer
  if initial? || pending?
    pending_writer
  elsif passing?
    passing_writer
  elsif failing?
    failing_writer
  end
end

#detail?Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/test_bench/output/output.rb', line 287

def detail?
  Detail.detail?(detail_policy, mode)
end

#failing?Boolean

Returns:

  • (Boolean)


283
284
285
# File 'lib/test_bench/output/output.rb', line 283

def failing?
  mode == Mode.failing
end

#initial?Boolean

Returns:

  • (Boolean)


271
272
273
# File 'lib/test_bench/output/output.rb', line 271

def initial?
  mode == Mode.initial
end

#merge(result) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/test_bench/output/output.rb', line 246

def merge(result)
  self.branch_count -= 1

  if not branched?
    pending_writer.sync = true

    self.mode = Mode.initial
  end

  if result
    writer = passing_writer
  else
    writer = failing_writer
  end

  writer.flush

  self.passing_writer = writer.device
  self.failing_writer = writer.alternate_device
end

#passing?Boolean

Returns:

  • (Boolean)


279
280
281
# File 'lib/test_bench/output/output.rb', line 279

def passing?
  mode == Mode.passing
end

#pending?Boolean

Returns:

  • (Boolean)


275
276
277
# File 'lib/test_bench/output/output.rb', line 275

def pending?
  mode == Mode.pending
end

#receive(event) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/test_bench/output/output.rb', line 65

def receive(event)
  case event
  when ContextStarted, TestStarted
    branch
  end

  if initial?
    handle(event)

  else
    self.mode = Mode.failing
    handle(event)

    self.mode = Mode.passing
    handle(event)

    self.mode = Mode.pending
    handle(event)
  end

  case event
  when ContextFinished, TestFinished
    merge(event.result)
  end
end