Class: TapOut::Reporters::PrettyReporter

Inherits:
Abstract
  • Object
show all
Defined in:
lib/tapout/reporters/pretty_reporter.rb

Overview

Pretty Reporter (by Paydro)

Constant Summary collapse

PADDING_SIZE =
4
PASS =
"PASS".ansi(:green)
FAIL =
"FAIL".ansi(:red)
ERROR =
"ERROR".ansi(:yellow)

Constants inherited from Abstract

Abstract::INTERNALS

Instance Method Summary collapse

Methods inherited from Abstract

#<<, #clean_backtrace, #code_snippet, #complete_cases, #exit_code, #finalize, #handle, inherited, #initialize, #note, #omit, #parse_source_location, #skip, #source, #tally, #tally_message

Constructor Details

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

Instance Method Details

#error(test) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/tapout/reporters/pretty_reporter.rb', line 95

def error(test)
  print pad_with_size("#{ERROR}")
  print " #{test['label']}"
  print " (%.2fs) " % (Time.now - @test_time)

  #message = exception.to_s.split("\n")[2..-1].join("\n")

  message = test['exception']['message']

  if bt = test['exception']['backtrace']
    _trace = clean_backtrace(bt)
  else
    _trace = filter_backtrace(bt)
  end

  trace = _trace.shift
  puts
  tabsize = 10
  puts message.tabto(tabsize)
  puts trace.tabto(tabsize)
  if depth = TapOut.trace
    puts _trace[0,depth].map{|l| l.tabto(tabsize) }.join("\n")
  end
end

#fail(test) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tapout/reporters/pretty_reporter.rb', line 67

def fail(test)
  print pad_with_size("#{FAIL}")
  print " #{test['label']}"
  print " (%.2fs) " % (Time.now - @test_time)

  #message = assertion.location[0] + "\n" + assertion.message #.gsub("\n","\n")
  #trace   = MiniTest::filter_backtrace(report[:exception].backtrace).first

  message = test['exception']['message']

  if bt = test['exception']['backtrace']
    _trace = clean_backtrace(bt)
  else
    _trace = clean_backtrace(bt)
  end

  puts
  tabsize = 10
  #puts pad(message, tabsize)
  puts message.tabto(tabsize)
  puts _trace.shift.tabto(tabsize)
  if depth = TapOut.trace
    puts _trace[0,depth].map{|l| l.tabto(tabsize) }.join("\n")
  end
  #show_captured_output
end

#finish_case(kase) ⇒ Object

def show_captured_output

      show_captured_stdout
      show_captured_stderr
    end

    def show_captured_stdout
      @stdout.rewind
      return if @stdout.eof?
      STDOUT.puts(<<-output.tabto(8))
\nSTDOUT:
#{@stdout.read}
      output
    end

    def show_captured_stderr
      @stderr.rewind
      return if @stderr.eof?
      STDOUT.puts(<<-output.tabto(8))
\nSTDERR:
#{@stderr.read}
      output
    end


159
160
161
162
163
# File 'lib/tapout/reporters/pretty_reporter.rb', line 159

def finish_case(kase)
  #if kase.size == 0
  #  puts pad("(No Tests)")
  #end
end

#finish_suite(final) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/tapout/reporters/pretty_reporter.rb', line 166

def finish_suite(final)
  #@@out.sync = old_sync if @@out.respond_to? :sync=

  total   = final['counts']['total'] || 0
  failure = final['counts']['fail']  || 0
  error   = final['counts']['error'] || 0
  skip    = final['counts']['skip']  || 0
  omit    = final['counts']['omit']  || 0
  #pass    = total - failure - error

  puts
  puts "Finished in #{'%.6f' % (Time.now - @time)} seconds."
  puts

  print "%d tests, " % total
  #print "%d assertions, " % suite.count_assertions
  print ("%d failures" % failure).ansi(:red) + ', '
  print ("%d errors" % error).ansi(:yellow) + ', '
  print ("%d pending" % skip).ansi(:cyan)
  puts
end

#finish_test(test) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/tapout/reporters/pretty_reporter.rb', line 126

def finish_test(test)
  puts
  #@test_count += 1
  #@assertion_count += inst._assertions
  #$stdout = STDOUT
  #$stderr = STDERR
end

#pad(str, size = PADDING_SIZE) ⇒ Object (private)



191
192
193
# File 'lib/tapout/reporters/pretty_reporter.rb', line 191

def pad(str, size=PADDING_SIZE)
  " " * size + str
end

#pad_with_size(str) ⇒ Object (private)



196
197
198
# File 'lib/tapout/reporters/pretty_reporter.rb', line 196

def pad_with_size(str)
  " " * (18 - str.size) + str
end

#pass(test) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/tapout/reporters/pretty_reporter.rb', line 55

def pass(test)
  print pad_with_size("#{PASS}")
  print " #{test['label']}"
  print " (%.2fs) " % (Time.now - @test_time)
  #if message
  #  message = test['source'].ansi(:magenta)
  #  message = message.to_s.tabto(10)
  #  puts(message)
  #end
end

#start_case(kase) ⇒ Object



33
34
35
36
37
# File 'lib/tapout/reporters/pretty_reporter.rb', line 33

def start_case(kase)
  #if kase.size > 0  # TODO: Don't have size yet?
    print "\n#{kase['label']}:\n"
  #end
end

#start_suite(suite) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tapout/reporters/pretty_reporter.rb', line 20

def start_suite(suite)
  #old_sync, @@out.sync = @@out.sync, true if io.respond_to? :sync=
  @suite  = suite
  @time   = Time.now
  #@stdout = StringIO.new
  #@stderr = StringIO.new
  #files = suite.collect{ |s| s.file }.join(' ')
#puts "Loaded suite #{suite.name}"
  puts "Suite seed: #{suite['seed']}" if suite['seed']
  puts "Started"
end

#start_test(test) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tapout/reporters/pretty_reporter.rb', line 40

def start_test(test)
  @test_time = Time.now
  @test = test
  #if @file != test.file
  #  @file = test.file
  #  puts(test.file)
  #end
  #print "    %-69s" % test.name
  #$stdout = @stdout
  #$stderr = @stderr
  #$stdout.rewind
  #$stderr.rewind
end