Class: Turn::PrettyReporter

Inherits:
Reporter show all
Defined in:
lib/turn/reporters/pretty_reporter.rb

Overview

Pretty Reporter (by Paydro)

Constant Summary collapse

PADDING_SIZE =
4

Constants included from Colorize

Colorize::COLORIZE, Colorize::ERROR, Colorize::FAIL, Colorize::PASS, Colorize::SKIP

Instance Attribute Summary

Attributes inherited from Reporter

#io

Instance Method Summary collapse

Methods inherited from Reporter

#initialize

Methods included from Colorize

blue, bold, error, fail, green, magenta, pass, red, skip

Constructor Details

This class inherits a constructor from Turn::Reporter

Instance Method Details

#error(exception) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/turn/reporters/pretty_reporter.rb', line 83

def error(exception)
  io.print pad_with_size("#{ERROR}")
  io.print " #{@test}"
  io.print " (%.2fs) " % (Time.now - @test_time)

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

  message = exception.message

  if exception.respond_to?(:backtrace)
    trace = filter_backtrace(exception.backtrace).first
  else
    trace = filter_backtrace(exception.location).first
  end

  io.puts
  io.puts message.tabto(10)
  io.puts trace.tabto(10)
end

#fail(assertion) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/turn/reporters/pretty_reporter.rb', line 59

def fail(assertion)
  io.print pad_with_size("#{FAIL}")
  io.print " #{@test}"
  io.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 = assertion.message

  if assertion.respond_to?(:backtrace)
    trace = filter_backtrace(assertion.backtrace).first
  else
    trace = filter_backtrace(assertion.location).first
  end

  io.puts
  #io.puts pad(message, 10)
  io.puts message.tabto(10)
  io.puts trace.tabto(10)
  #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: #Turn::PrettyReporter.@[email protected]

  output
end

def show_captured_stderr
  @stderr.rewind
  return if @stderr.eof?
  STDOUT.puts(<<-output.tabto(8))

nSTDERR: #Turn::PrettyReporter.@[email protected]

  output
end


142
143
144
145
146
# File 'lib/turn/reporters/pretty_reporter.rb', line 142

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

#finish_suite(suite) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/turn/reporters/pretty_reporter.rb', line 149

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

  total   = suite.count_tests
  failure = suite.count_failures
  error   = suite.count_errors
  #pass    = total - failure - error

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

  io.print "%d tests, " % total
  io.print "%d assertions, " % suite.count_assertions
  io.print Colorize.fail( "%d failures" % failure) + ', '
  io.print Colorize.error("%d errors" % error) #+ ', '
  #io.puts  Colorize.cyan( "%d skips" % skips ) #TODO
  io.puts
end

#finish_test(test) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/turn/reporters/pretty_reporter.rb', line 109

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

#pass(message = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/turn/reporters/pretty_reporter.rb', line 47

def pass(message=nil)
  io.print pad_with_size("#{PASS}")
  io.print " #{@test}"
  io.print " (%.2fs) " % (Time.now - @test_time)
  if message
    message = Colorize.magenta(message)
    message = message.to_s.tabto(10)
    io.puts(message)
  end
end

#start_case(kase) ⇒ Object



25
26
27
28
29
# File 'lib/turn/reporters/pretty_reporter.rb', line 25

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

#start_suite(suite) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/turn/reporters/pretty_reporter.rb', line 12

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(' ')
  io.puts "Loaded suite #{suite.name}"
  #io.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
  io.puts "Started"
end

#start_test(test) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/turn/reporters/pretty_reporter.rb', line 32

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