Class: TestBench::Session::Output

Inherits:
Object
  • Object
show all
Includes:
Output, Events
Defined in:
lib/test_bench/session/output.rb,
lib/test_bench/session/output/get.rb,
lib/test_bench/session/output/writer.rb,
lib/test_bench/session/output/writer/buffer.rb,
lib/test_bench/session/output/writer/defaults.rb,
lib/test_bench/session/output/writer/substitute.rb,
lib/test_bench/session/output/writer/buffer/interactive.rb,
lib/test_bench/session/output/writer/buffer/interactive/viewport.rb

Defined Under Namespace

Modules: Detail, Get, Mode Classes: Writer

Constant Summary

Constants included from Events

Events::Commented, Events::ContextFinished, Events::ContextSkipped, Events::ContextStarted, Events::Detailed, Events::Failed, Events::FixtureFinished, Events::FixtureStarted, Events::TestFinished, Events::TestSkipped, Events::TestStarted

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Events

each_type

Instance Attribute Details

#branch_count ⇒ Object



32
33
34
# File 'lib/test_bench/session/output.rb', line 32

def branch_count
  @branch_count ||= 0
end

#detail_policy ⇒ Object Also known as: detail



37
38
39
# File 'lib/test_bench/session/output.rb', line 37

def detail_policy
  @detail_policy ||= Detail.default
end

#failing_writer ⇒ Object



17
18
19
# File 'lib/test_bench/session/output.rb', line 17

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

#failures ⇒ Object



22
23
24
# File 'lib/test_bench/session/output.rb', line 22

def failures
  @failures ||= 0
end

#mode ⇒ Object



27
28
29
# File 'lib/test_bench/session/output.rb', line 27

def mode
  @mode ||= Mode.initial
end

#passing_writer ⇒ Object



12
13
14
# File 'lib/test_bench/session/output.rb', line 12

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

#pending_writer ⇒ Object



7
8
9
# File 'lib/test_bench/session/output.rb', line 7

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

Instance Method Details

#branch ⇒ Object



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/test_bench/session/output.rb', line 263

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)


300
301
302
# File 'lib/test_bench/session/output.rb', line 300

def branched?
  branch_count > 0
end

#comment(text, quote, heading) ⇒ Object



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

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

    if not writer.styling?
      writer.
        indent.
        puts('- - -')
    end
  end

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

  if not quote
    writer.
      indent.
      puts(text)
  else
    text.each_line(chomp: true) do |line|
      writer.
        indent.
        style(:faint).
        print('> ').
        style(:reset_intensity).
        puts(line)
    end
  end
end

#configure(detail: nil, **arguments) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/test_bench/session/output.rb', line 43

def configure(detail: nil, **arguments)
  if not detail.nil?
    self.detail_policy = detail
  end

  Writer.configure(self, **arguments, attr_name: :pending_writer)
end

#current_writer ⇒ Object Also known as: writer



252
253
254
255
256
257
258
259
260
# File 'lib/test_bench/session/output.rb', line 252

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

#detail? ⇒ Boolean

Returns:

  • (Boolean)


320
321
322
# File 'lib/test_bench/session/output.rb', line 320

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

#failing? ⇒ Boolean

Returns:

  • (Boolean)


316
317
318
# File 'lib/test_bench/session/output.rb', line 316

def failing?
  mode == Mode.failing
end

#initial? ⇒ Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/test_bench/session/output.rb', line 304

def initial?
  mode == Mode.initial
end

#merge(result) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/test_bench/session/output.rb', line 279

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)


312
313
314
# File 'lib/test_bench/session/output.rb', line 312

def passing?
  mode == Mode.passing
end

#pending? ⇒ Boolean

Returns:

  • (Boolean)


308
309
310
# File 'lib/test_bench/session/output.rb', line 308

def pending?
  mode == Mode.pending
end

#receive(event_data) ⇒ Object



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

def receive(event_data)
  case event_data.type
  when ContextStarted.event_type, TestStarted.event_type
    branch
  end

  if initial?
    handle(event_data)

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

    self.mode = Mode.passing
    handle(event_data)

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

  case event_data.type
  when ContextFinished.event_type, TestFinished.event_type
    _title, result = event_data.data
    merge(result)
  end
end