Class: Test::Reporters::Outline

Inherits:
Abstract
  • Object
show all
Defined in:
lib/test/reporters/outline.rb

Instance Attribute Summary

Attributes inherited from Abstract

#runner

Instance Method Summary collapse

Methods inherited from Abstract

#clean_backtrace, #code, #end_test, #file, #file_and_line, #file_and_line_array, inherited, #initialize, #line, #record, registry, #skip_case, #skip_test, #subtotal, #tally, #timestamp, #total, #total_count

Constructor Details

This class inherits a constructor from Test::Reporters::Abstract

Instance Method Details

#begin_case(tc) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/test/reporters/outline.rb', line 18

def begin_case(tc)
  lines = tc.to_s.split("\n")
  label = lines.shift
  if tc.respond_to?(:type)
    tabs "#{tc.type}: #{label}".ansi(:bold)
    tabs lines.join("\n"), 2 unless lines.empty?
  else
    tabs "#{label}".ansi(:bold)
    tabs lines.join("\n"), 2 unless lines.empty?
  end
  @tab += 2
end

#begin_suite(suite) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/test/reporters/outline.rb', line 9

def begin_suite(suite)
  @tab   = 0
  @start_time = Time.now
  @start_test_cache = {}

  timer_reset
end

#begin_test(test) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/test/reporters/outline.rb', line 32

def begin_test(test)
   if test.respond_to?(:topic) && test.topic
     topic = test.topic.to_s
     @start_test_cache[topic] ||= (
       tabs "#{topic}"
       true
     )
   end
   timer_reset
end

#clockObject



145
146
147
148
# File 'lib/test/reporters/outline.rb', line 145

def clock
  secs = Time.now - @start_time
  return "%0.5fs" % [secs.to_s]
end

#end_case(tcase) ⇒ Object



86
87
88
# File 'lib/test/reporters/outline.rb', line 86

def end_case(tcase)
  @tab -= 2
end

#end_suite(suite) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/test/reporters/outline.rb', line 91

def end_suite(suite)
  puts

  #unless record[:omit].empty?
  #  puts "\nOMITTED:\n\n"
  #  puts record[:omit].map{ |u| u.to_s }.sort.join('  ')
  #  puts
  #end

  #unless record[:todo].empty?
  #  puts "\nPENDING:\n\n"
  #  record[:pending].each do |test, exception|
  #    puts "#{test}".tabto(4)
  #    puts "#{file_and_line(exception)}".tabto(4)
  #    puts
  #  end
  #end

  #unless record[:fail].empty?
  #  puts "\nFAILURES:\n\n"
  #  record[:fail].reverse_each do |test, exception|
  #
  #    s = []
  #    s << "#{test}".ansi(:red)
  #    s << "#{file_and_line(exception)}".ansi(:bold)
  #    s <<  "#{exception}"
  #    s <<  code_snippet(exception)
  #    #puts "    #{exception.backtrace[0]}"
  #    puts s.join("\n").tabto(4)
  #  end
  #end

  #unless record[:error].empty?
  #  puts "\nERRORS:\n\n"
  #  record[:error].reverse_each do |test, exception|
  #    trace = clean_backtrace(exception)[1..-1]
  # 
  #     s = []
  #    s << "#{test}".ansi(:red, :bold)
  #    s << "#{exception.class} @ #{file_and_line(exception)}".ansi(:bold)
  #    s << "#{exception}"
  #    s << code_snippet(exception)
  #    #s << trace.join("\n") unless trace.empty?
  #    puts s.join("\n").tabto(4)
  #  end
  #end

  puts
  puts timestamp
  puts
  puts tally
end

#error(test, exception) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/test/reporters/outline.rb', line 62

def error(test, exception)
  tabs "#{test}".ansi(:red, :bold)

  s = []
  s << "#{exception.class}"
  s << "#{exception}"
  s << "#{file_and_line(exception)}"
  s << code(exception)
  #s << trace.join("\n") unless trace.empty?
  tabs s.join("\n"), 4
end

#fail(test, exception) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/test/reporters/outline.rb', line 50

def fail(test, exception)
  tabs "#{test}".ansi(:red)

  s = []
  s << "#{exception}"
  s << "#{file_and_line(exception)}"
  s << code(exception)
  #puts "    #{exception.backtrace[0]}"
  tabs s.join("\n"), 4
end

#omit(test, exception) ⇒ Object



81
82
83
# File 'lib/test/reporters/outline.rb', line 81

def omit(test, exception)
  tabs "#{test}".ansi(:cyan)
end

#pass(test) ⇒ Object



45
46
47
# File 'lib/test/reporters/outline.rb', line 45

def pass(test)
  tabs "#{test}".ansi(:green)
end

#tabs(str, indent = 0) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/test/reporters/outline.rb', line 163

def tabs(str, indent=0)
  if str
    puts(str.tabto(@tab + indent))
  else
    puts
  end
end

#timerObject



151
152
153
154
155
# File 'lib/test/reporters/outline.rb', line 151

def timer
  secs  = Time.now - @time
  @time = Time.now
  return "%0.5fs" % [secs.to_s]
end

#timer_resetObject



158
159
160
# File 'lib/test/reporters/outline.rb', line 158

def timer_reset
  @time = Time.now
end

#todo(test, exception) ⇒ Object



75
76
77
78
# File 'lib/test/reporters/outline.rb', line 75

def todo(test, exception)
  tabs "#{test}".ansi(:yellow)
  tabs "#{file_and_line(exception)}", 4
end