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_countObject



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

def branch_count
  @branch_count ||= 0
end

#detail_policyObject 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_writerObject



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

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

#failuresObject



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

def failures
  @failures ||= 0
end

#modeObject



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

def mode
  @mode ||= Mode.initial
end

#passing_writerObject



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

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

#pending_writerObject



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

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

Instance Method Details

#branchObject



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/test_bench/session/output.rb', line 272

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)


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

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
251
252
253
254
255
256
257
258
259
# 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

      if writer.styling?
        writer.
          style(:white_bg).
          print(' ').
          style(:reset_bg).
          print(' ')
      else
        writer.
          print('> ')
      end

      writer.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_writerObject Also known as: writer



261
262
263
264
265
266
267
268
269
# File 'lib/test_bench/session/output.rb', line 261

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

#detail?Boolean

Returns:

  • (Boolean)


329
330
331
# File 'lib/test_bench/session/output.rb', line 329

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

#failing?Boolean

Returns:

  • (Boolean)


325
326
327
# File 'lib/test_bench/session/output.rb', line 325

def failing?
  mode == Mode.failing
end

#initial?Boolean

Returns:

  • (Boolean)


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

def initial?
  mode == Mode.initial
end

#merge(result) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/test_bench/session/output.rb', line 288

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)


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

def passing?
  mode == Mode.passing
end

#pending?Boolean

Returns:

  • (Boolean)


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

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