Class: TestBench::Output::Buffer

Inherits:
Fixture::Output::Capture
  • Object
show all
Defined in:
lib/test_bench/output/buffer.rb

Defined Under Namespace

Modules: Record

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_outputObject



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

def raw_output
  @raw_output ||= Raw.new
end

#writerObject

Returns the value of attribute writer.



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

def writer
  @writer
end

Class Method Details

.build(verbose: nil, detail: nil, omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, device: nil, styling: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# 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

Instance Method Details

#buffering?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/test_bench/output/buffer.rb', line 84

def buffering?
  stack_depth.nonzero?
end

#exit_contextObject



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

def exit_context(*)
  super

  flush unless buffering?
end

#finish_batch(final_record, result) ⇒ Object



67
68
69
70
71
72
73
74
# 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_fixtureObject



37
38
39
40
41
# File 'lib/test_bench/output/buffer.rb', line 37

def finish_fixture(*)
  super

  flush unless buffering?
end

#finish_testObject



31
32
33
34
35
# File 'lib/test_bench/output/buffer.rb', line 31

def finish_test(*)
  super

  flush unless buffering?
end

#flushObject



76
77
78
79
80
81
82
# 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) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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

#stackObject



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

def stack
  @stack ||= []
end

#stack_depthObject



88
89
90
# File 'lib/test_bench/output/buffer.rb', line 88

def stack_depth
  stack.length
end

#start_batch(record) ⇒ Object



61
62
63
64
65
# File 'lib/test_bench/output/buffer.rb', line 61

def start_batch(record)
  record.start_batch(stack_depth)

  stack.push(record)
end