Class: QED::Reporter::Linear

Inherits:
Abstract show all
Defined in:
lib/qed/reporter/linear.rb

Overview

Linear reporter limits each step to a single line.

Constant Summary

Constants inherited from Abstract

Abstract::DEFAULT_TRACE_COUNT, Abstract::INFO_SIGNAL, Abstract::INTERNALS

Instance Attribute Summary

Attributes inherited from Abstract

#io, #record, #session

Instance Method Summary collapse

Methods inherited from Abstract

After, Before, When, #after_demo, #after_eval, #after_import, #after_proc, #after_step, #before_eval, #before_import, #before_proc, #before_step, #call, #clean_backtrace, #code_snippet, #count_demo, #count_error, #count_fail, #count_pass, #count_step, #demo, #demos, #errors, #eval, #fails, #file_and_line, #file_line, #get_tally, #import, #initialize, #localize_file, #omits, #passes, #print_tally, #print_time, #proc, #relative_file, #rule, #sane_backtrace, #source, #step, #steps, #structured_code_snippet, #success?, #trace?, #trace_count

Constructor Details

This class inherits a constructor from QED::Reporter::Abstract

Instance Method Details

#after_session(session) ⇒ Object


88
89
90
91
92
# File 'lib/qed/reporter/linear.rb', line 88

def after_session(session)
  puts "[INFO] %s demos, %s steps: %s failures, %s errors (%s/%s assertions)" % get_tally
  puts "[INFO] Finished in %.5f seconds." % [Time.now - @start_time]
  puts "[INFO] End Session @ #{Time.now}".ansi(:bold)
end

#before_applique(step) ⇒ Object


25
26
27
28
29
30
31
32
# File 'lib/qed/reporter/linear.rb', line 25

def before_applique(step)
  super(step)  #post

  str = "[NOTE] #{step.explain.gsub(/\s+/,' ')} "[0,@width]
  pad = @width - str.size + 1
  print str + (' ' * pad)
  puts "[#{timestamp}]"
end

#before_demo(demo) ⇒ Object


19
20
21
22
# File 'lib/qed/reporter/linear.rb', line 19

def before_demo(demo)
  file = localize_file(demo.file)
  puts "[DEMO] #{file}".ansi(:bold)
end

#before_session(session) ⇒ Object


12
13
14
15
16
# File 'lib/qed/reporter/linear.rb', line 12

def before_session(session)
  @width = ANSI::Terminal.terminal_width - 12
  @start_time = Time.now
  puts "[INFO] Session @ #{Time.now}".ansi(:bold)
end

#error(step, exception) ⇒ Object


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/qed/reporter/linear.rb', line 67

def error(step, exception)
  super(step, exception)

  print_step(step, 'ERRO', :red)

  #puts "ERROR".ansi(:red)

  s = []
  s << assertion.class.name
  s << assertion.message

  backtrace = sane_backtrace(assertion)
  backtrace.each do |bt|
    s << bt
    s << code_snippet(bt)
  end

  puts s.join("\n").tabto(8)
end

#fail(step, assertion) ⇒ Object


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/qed/reporter/linear.rb', line 46

def fail(step, assertion)
  super(step, assertion)

  print_step(step, 'FAIL', :red)

  #puts "FAIL".ansi(:red)

  s = []
  s << assertion.class.name
  s << assertion.message

  backtrace = sane_backtrace(assertion)
  backtrace.each do |bt|
    s << bt
    s << code_snippet(bt)
  end

  puts s.join("\n").tabto(8)
end

#pass(step) ⇒ Object


35
36
37
38
39
40
41
42
43
# File 'lib/qed/reporter/linear.rb', line 35

def pass(step)
  super(step)

  print_step(step, 'PASS', :green)

  #s = []
  #s << "PASS".ansi(:green)
  #puts s.join("\n")
end

#postObject (private)


113
114
115
116
# File 'lib/qed/reporter/linear.rb', line 113

def post
  io.puts if @appendable
  @appendable = false
end

101
102
103
104
# File 'lib/qed/reporter/linear.rb', line 101

def print(str)
  @appendable = true
  io.print str
end

119
120
121
122
123
124
125
126
127
128
# File 'lib/qed/reporter/linear.rb', line 119

def print_step(step, stat, *color)
  desc = step.explain.gsub(/\s+/,' ')
  if desc.start_with?('=') or desc.start_with?('#')
    desc = desc.ansi(:magenta)
  end
  str = "[#{stat}] #{desc} "[0,@width]
  pad = @width - str.unansi.size + 1
  print (str + (' ' * pad)).ansi(*color)
  puts "[#{timestamp}]"
end

#puts(str) ⇒ Object (private)


107
108
109
110
# File 'lib/qed/reporter/linear.rb', line 107

def puts(str)
  @appendable = false
  io.puts str
end

#timestampObject (private)


96
97
98
# File 'lib/qed/reporter/linear.rb', line 96

def timestamp
  (Time.now - @start_time).to_s[0,8]
end