Class: Test::Reporters::Abstract

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

Overview

Test Reporter Base Class

Direct Known Subclasses

AbstractHash, Dotprogress, Html, Outline, Progress, Summary, Tap

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Abstract

Returns a new instance of Abstract.



31
32
33
34
35
36
37
# File 'lib/test/reporters/abstract.rb', line 31

def initialize(runner)
  @runner = runner
  #@source = {}

  # in case start_suite is overridden
  @start_time = Time.now
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



40
41
42
# File 'lib/test/reporters/abstract.rb', line 40

def runner
  @runner
end

Class Method Details

.inherited(base) ⇒ Object



21
22
23
# File 'lib/test/reporters/abstract.rb', line 21

def self.inherited(base)
  registry << base
end

.registryObject



26
27
28
# File 'lib/test/reporters/abstract.rb', line 26

def self.registry
  @registry ||= []
end

Instance Method Details

#begin_case(test_case) ⇒ Object



48
49
# File 'lib/test/reporters/abstract.rb', line 48

def begin_case(test_case)
end

#begin_suite(test_suite) ⇒ Object



43
44
45
# File 'lib/test/reporters/abstract.rb', line 43

def begin_suite(test_suite)
  @start_time = Time.now
end

#begin_test(test) ⇒ Object



52
53
# File 'lib/test/reporters/abstract.rb', line 52

def begin_test(test)
end

#clean_backtrace(exception) ⇒ Array (protected)

Remove reference to lemon library from backtrace.

Parameters:

  • exception (Exception)

    The error that was rasied.

Returns:

  • (Array)

    filtered backtrace



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/test/reporters/abstract.rb', line 166

def clean_backtrace(exception)
  trace = (Exception === exception ? exception.backtrace : exception)
  return trace if $DEBUG
  trace = trace.reject{ |t| RUBY_IGNORE_CALLERS.any?{ |r| r =~ t }}
  trace = trace.map do |t|
    i = t.index(':in')
    i ? t[0...i] : t
  end
  #if trace.empty?
  #  exception
  #else
  #  exception.set_backtrace(trace) if Exception === exception
  #  exception
  #end
  trace.uniq
end

#code(source, line = nil) ⇒ CodeSnippet (protected)

That an exception, backtrace or source code text and line number and return a CodeSnippet object.

Returns:



187
188
189
190
191
192
193
194
# File 'lib/test/reporters/abstract.rb', line 187

def code(source, line=nil)
  case source
  when Exception, Array
    CodeSnippet.from_backtrace(clean_backtrace(source))
  else
    CodeSnippet.new(source, line)
  end
end

#end_case(test_case) ⇒ Object



92
93
# File 'lib/test/reporters/abstract.rb', line 92

def end_case(test_case)
end

#end_suite(test_suite) ⇒ Object



96
97
# File 'lib/test/reporters/abstract.rb', line 96

def end_suite(test_suite)
end

#end_test(test) ⇒ Object



88
89
# File 'lib/test/reporters/abstract.rb', line 88

def end_test(test)
end

#error(test, exception) ⇒ Object



76
77
# File 'lib/test/reporters/abstract.rb', line 76

def error(test, exception)
end

#fail(test, exception) ⇒ Object



72
73
# File 'lib/test/reporters/abstract.rb', line 72

def fail(test, exception)
end

#file(exception) ⇒ Object (protected)



225
226
227
# File 'lib/test/reporters/abstract.rb', line 225

def file(exception)
  file_and_line_array(exception).first
end

#file_and_line(exception) ⇒ Object (protected)



201
202
203
204
205
206
207
# File 'lib/test/reporters/abstract.rb', line 201

def file_and_line(exception)
  line = clean_backtrace(exception)[0]
  return "" unless line
  i = line.rindex(':in')
  line = i ? line[0...i] : line
  File.basename(line)
end

#file_and_line_array(exception) ⇒ Object (protected)



210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/test/reporters/abstract.rb', line 210

def file_and_line_array(exception)
  case exception
  when Exception
    line = exception.backtrace[0]
  else
    line = exception[0] # backtrace
  end
  return ["", 0] unless line
  i = line.rindex(':in')
  line = i ? line[0...i] : line
  f, l = File.basename(line).split(':')
  return [f, l.to_i]
end

#line(exception) ⇒ Object (protected)



230
231
232
# File 'lib/test/reporters/abstract.rb', line 230

def line(exception)
  file_and_line_array(exception).last
end

#omit(test, exception) ⇒ Object

Report an omitted test.



84
85
# File 'lib/test/reporters/abstract.rb', line 84

def omit(test, exception)
end

#pass(test) ⇒ Object



68
69
# File 'lib/test/reporters/abstract.rb', line 68

def pass(test)
end

#recordObject (protected)



101
102
103
# File 'lib/test/reporters/abstract.rb', line 101

def record
  runner.recorder
end

#skip_case(test_case) ⇒ Object



56
57
# File 'lib/test/reporters/abstract.rb', line 56

def skip_case(test_case)
end

#skip_test(test) ⇒ Object



60
61
# File 'lib/test/reporters/abstract.rb', line 60

def skip_test(test)
end

#subtotalObject (protected)



136
137
138
139
140
# File 'lib/test/reporters/abstract.rb', line 136

def subtotal
  [:todo, :pass, :fail, :error, :omit].inject(0) do |s,r|
    s += record[r.to_sym].size; s
  end
end

#tallyString (protected)

Common tally stamp any reporter can use.

Returns:



147
148
149
150
151
152
153
154
# File 'lib/test/reporters/abstract.rb', line 147

def tally
  sizes = %w{pass fail error todo omit}.map{ |r| record[r.to_sym].size }
  data  = [total] + sizes

  s = "%s tests: %s passing, %s failures, %s errors, %s pending, %s omissions" % data
  #s += "(#{uncovered_units.size} uncovered, #{undefined_units.size} undefined)" if cover?
  s
end

#timestampObject (protected)

Common timestamp any reporter can use.



124
125
126
127
128
# File 'lib/test/reporters/abstract.rb', line 124

def timestamp
  seconds = Time.now - @start_time

  "Finished in %.5fs, %.2f tests/s." % [seconds, total/seconds]
end

#todo(test, exception) ⇒ Object

Report a pending test.



80
81
# File 'lib/test/reporters/abstract.rb', line 80

def todo(test, exception)
end

#totalObject (protected)



131
132
133
# File 'lib/test/reporters/abstract.rb', line 131

def total
  @total ||= subtotal
end

#total_count(suite) ⇒ Object (protected)

Count up the total number of tests.



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/test/reporters/abstract.rb', line 111

def total_count(suite)
  c = 0
  suite.each do |tc|
    if tc.respond_to?(:each)
      c += total_count(tc)
    else
      c += 1
    end
  end
  return c
end