class Test::Reporters::Abstract

Test Reporter Base Class

Constants

TITLES

TODO: lump skipped and omitted into one group ?

Attributes

runner[R]

Public Class Methods

inherited(base) click to toggle source
# File lib/rubytest/format/abstract.rb, line 12
def self.inherited(base)
  registry << base
end
new(runner) click to toggle source
# File lib/rubytest/format/abstract.rb, line 22
def initialize(runner)
  @runner = runner
  #@source = {}

  # in case start_suite is overridden
  @start_time = Time.now
end
registry() click to toggle source
# File lib/rubytest/format/abstract.rb, line 17
def self.registry
  @registry ||= []
end

Public Instance Methods

begin_case(test_case) click to toggle source
# File lib/rubytest/format/abstract.rb, line 39
def begin_case(test_case)
end
begin_suite(test_suite) click to toggle source
# File lib/rubytest/format/abstract.rb, line 34
def begin_suite(test_suite)
  @start_time = Time.now
end
begin_test(test) click to toggle source
# File lib/rubytest/format/abstract.rb, line 43
def begin_test(test)
end
end_case(test_case) click to toggle source
# File lib/rubytest/format/abstract.rb, line 79
def end_case(test_case)
end
end_suite(test_suite) click to toggle source
# File lib/rubytest/format/abstract.rb, line 83
def end_suite(test_suite)
end
end_test(test) click to toggle source
# File lib/rubytest/format/abstract.rb, line 75
def end_test(test)
end
error(test, exception) click to toggle source

Report a test error.

# File lib/rubytest/format/abstract.rb, line 67
def error(test, exception)
end
fail(test, exception) click to toggle source
# File lib/rubytest/format/abstract.rb, line 63
def fail(test, exception)
end
pass(test) click to toggle source
# File lib/rubytest/format/abstract.rb, line 59
def pass(test)
end
skip_case(test_case) click to toggle source
# File lib/rubytest/format/abstract.rb, line 47
def skip_case(test_case)
end
skip_test(test) click to toggle source
# File lib/rubytest/format/abstract.rb, line 51
def skip_test(test)
end
todo(test, exception) click to toggle source

Report a pending test.

# File lib/rubytest/format/abstract.rb, line 71
def todo(test, exception)
end

Protected Instance Methods

clean_backtrace(exception) click to toggle source

Remove reference to lemon library from backtrace.

@param [Exception] exception

The error that was rasied.

@return [Array] filtered backtrace

# File lib/rubytest/format/abstract.rb, line 183
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.map{ |bt| File.localname(bt) }
end
code(source, line=nil) click to toggle source

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

@return [CodeSnippet] code snippet

# File lib/rubytest/format/abstract.rb, line 204
def code(source, line=nil)
  case source
  when Exception
    CodeSnippet.from_backtrace(clean_backtrace(source.backtrace))
  when Array
    CodeSnippet.from_backtrace(clean_backtrace(source))
  else
    CodeSnippet.new(source, line)
  end
end
file(exception) click to toggle source
# File lib/rubytest/format/abstract.rb, line 240
def file(exception)
  file_and_line_array(exception).first
end
file_and_line(exception) click to toggle source
# File lib/rubytest/format/abstract.rb, line 216
def file_and_line(exception)
  line = clean_backtrace(exception)[0]
  return "" unless line
  i = line.rindex(':in')
  line = i ? line[0...i] : line
  File.localname(line)
end
file_and_line_array(exception) click to toggle source
# File lib/rubytest/format/abstract.rb, line 225
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.localname(line).split(':')
  return [f, l.to_i]
end
line(exception) click to toggle source
# File lib/rubytest/format/abstract.rb, line 245
def line(exception)
  file_and_line_array(exception).last
end
record() click to toggle source
# File lib/rubytest/format/abstract.rb, line 88
def record
  runner.recorder
end
subtotal() click to toggle source
# File lib/rubytest/format/abstract.rb, line 123
def subtotal
  [:todo, :pass, :fail, :error, :omit, :skip].inject(0) do |s,r|
    s += record[r.to_sym].size; s
  end
end
tally() click to toggle source

Common tally stamp any reporter can use.

@return [String] tally stamp

# File lib/rubytest/format/abstract.rb, line 145
def tally
  sizes  = {}
  names  = %w{pass error fail todo omit skip}.map{ |n| n.to_sym }
  names.each do |r|
    sizes[r] = record[r].size
  end

  #names.unshift(:tests)
  #sizes[:tests] = total

  s = []
  names.each do |n|
    next unless sizes[n] > 0
    s << tally_item(n, sizes)
  end

  'Executed ' + "#{total}".ansi(:bold) + ' tests with ' + s.join(', ') + '.'
end
tally_item(name, sizes) click to toggle source
# File lib/rubytest/format/abstract.rb, line 165
def tally_item(name, sizes)
  x = []
  x << "%s" % sizes[name].to_s.ansi(:bold)
  x << " %s" % TITLES[name].downcase
  x << " (%.1f%%)" % ((sizes[name].to_f/total*100)) if runner.verbose?
  x.join('')
end
timestamp() click to toggle source

Common timestamp any reporter can use.

# File lib/rubytest/format/abstract.rb, line 111
def timestamp
  seconds = Time.now - @start_time

  "Finished in %.5fs, %.2f tests/s." % [seconds, total/seconds]
end
total() click to toggle source
# File lib/rubytest/format/abstract.rb, line 118
def total
  @total ||= subtotal
end
total_count(suite) click to toggle source

Count up the total number of tests.

# File lib/rubytest/format/abstract.rb, line 98
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