class TestBench::Output::Buffer

Attributes

raw_output[W]
writer[RW]

Public Class Methods

build(verbose: nil, detail: nil, omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, device: nil, styling: nil) click to toggle source
# File lib/test_bench/output/buffer.rb, line 15
def self.build(verbose: nil, detail: nil, omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, device: nil, styling: nil)
  instance = new

  raw_output = Raw.configure(instance, verbose: verbose, detail: detail, omit_backtrace_pattern: omit_backtrace_pattern, reverse_backtraces: reverse_backtraces, writer: writer, device: device, styling: styling)

  instance.writer = raw_output.writer

  instance
end

Public Instance Methods

buffering?() click to toggle source
# File lib/test_bench/output/buffer.rb, line 84
def buffering?
  stack_depth.nonzero?
end
exit_context(*) click to toggle source
Calls superclass method
# File lib/test_bench/output/buffer.rb, line 25
def exit_context(*)
  super

  flush unless buffering?
end
finish_batch(final_record, result) click to toggle source
# File lib/test_bench/output/buffer.rb, line 67
def finish_batch(final_record, result)
  first_record = stack.pop

  batch_data = first_record.batch_data
  batch_data.result = result

  final_record.batch_data = first_record.batch_data
end
finish_fixture(*) click to toggle source
Calls superclass method
# File lib/test_bench/output/buffer.rb, line 37
def finish_fixture(*)
  super

  flush unless buffering?
end
finish_test(*) click to toggle source
Calls superclass method
# File lib/test_bench/output/buffer.rb, line 31
def finish_test(*)
  super

  flush unless buffering?
end
flush() click to toggle source
# File lib/test_bench/output/buffer.rb, line 76
def flush
  records.each do |record|
    record.forward(raw_output)
  end

  records.clear
end
new_record(signal, data) click to toggle source
Calls superclass method
# File lib/test_bench/output/buffer.rb, line 43
def new_record(signal, data)
  record = super

  record.extend(Record)

  case signal
  when :enter_context, :start_test, :start_fixture
    start_batch(record)

  when :exit_context, :finish_test, :finish_fixture
    result = record.data.last

    finish_batch(record, result)
  end

  record
end
raw_output() click to toggle source
# File lib/test_bench/output/buffer.rb, line 6
def raw_output
  @raw_output ||= Raw.new
end
stack() click to toggle source
# File lib/test_bench/output/buffer.rb, line 11
def stack
  @stack ||= []
end
stack_depth() click to toggle source
# File lib/test_bench/output/buffer.rb, line 88
def stack_depth
  stack.length
end
start_batch(record) click to toggle source
# File lib/test_bench/output/buffer.rb, line 61
def start_batch(record)
  record.start_batch(stack_depth)

  stack.push(record)
end