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
TAB_SIZE =
10

Constants included from Colorize

Colorize::COLORLESS_TERMINALS, 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, color_supported?, #colorize?, colorize?, error, fail, green, magenta, pass, red, skip

Constructor Details

This class inherits a constructor from Turn::Reporter

Instance Method Details

#error(exception, message = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/turn/reporters/pretty_reporter.rb', line 89

def error(exception, message=nil)
  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

  _trace = if exception.respond_to?(:backtrace)
             clean_backtrace(exception.backtrace)
           else
             clean_backtrace(exception.location)
           end

  io.puts
  io.puts message.tabto(TAB_SIZE)
  io.puts _trace.map{|l| l.tabto(TAB_SIZE) }.join("\n")
end

#fail(assertion, message = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/turn/reporters/pretty_reporter.rb', line 62

def fail(assertion, message=nil)
  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

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

  io.puts
  #io.puts pad(message, tabsize)
  io.puts message.tabto(TAB_SIZE)

  cnt = @trace ? @trace.to_i : _trace.size
  io.puts _trace[0, cnt].map{|l| l.tabto(TAB_SIZE) }.join("\n")

  #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


162
163
164
165
166
# File 'lib/turn/reporters/pretty_reporter.rb', line 162

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

#finish_suite(suite) ⇒ Object



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

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



129
130
131
132
133
134
135
# File 'lib/turn/reporters/pretty_reporter.rb', line 129

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

#pass(message = nil) ⇒ Object



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

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

#skip(exception, message = nil) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/turn/reporters/pretty_reporter.rb', line 110

def skip(exception, message=nil)
  io.print pad_with_size("#{SKIP}")
  io.print " #{@test}"
  io.print " (%.2fs) " % (Time.now - @test_time)

  message ||= exception.message

  _trace = if exception.respond_to?(:backtrace)
             clean_backtrace(exception.backtrace)
           else
             clean_backtrace(exception.location)
           end

  io.puts
  io.puts message.tabto(TAB_SIZE)
  io.puts _trace.map{|l| l.tabto(TAB_SIZE) }.join("\n")
end

#start_case(kase) ⇒ Object



28
29
30
31
32
# File 'lib/turn/reporters/pretty_reporter.rb', line 28

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



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/turn/reporters/pretty_reporter.rb', line 15

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 (#{suite.seed})"
end

#start_test(test) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/turn/reporters/pretty_reporter.rb', line 35

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