Class: Turn::OutlineReporter

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

Overview

Outline Reporter is Turn’s Original.

– TODO: Should we fit reporter output to width of console?

y8: Yes. we should, but it's a kinda tricky, if you want to make it
    cross-platform. (See https://github.com/cldwalker/hirb/blob/master/lib/hirb/util.rb#L61)

TODO: Running percentages? TODO: Cleanup me! ++

Constant Summary collapse

TAB_SIZE =
8

Constants included from Colorize

Colorize::COLORLESS_TERMINALS

Instance Attribute Summary

Attributes inherited from Reporter

#io

Instance Method Summary collapse

Methods inherited from Reporter

#finish_case, #initialize

Methods included from Colorize

blue, bold, color_supported?, colorize?, #colorize?, error, fail, green, included, magenta, pass, red, skip

Constructor Details

This class inherits a constructor from Turn::Reporter

Instance Method Details

#error(exception) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/turn/reporters/outline_reporter.rb', line 94

def error(exception)
  io.puts " %s %s" % [ticktock, ERROR]

  message = []
  message << Colorize.bold(exception.message)
  message << "Exception `#{exception.class}' at:"
  message << clean_backtrace(exception.backtrace).join("\n")
  message = message.join("\n")

  io.puts(message.tabto(TAB_SIZE))

  #io.puts "STDERR:".tabto(TAB_SIZE)
  show_captured_output
end

#fail(assertion) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/turn/reporters/outline_reporter.rb', line 73

def fail(assertion)
  io.puts " %s %s" % [ticktock, FAIL]

  message = []
  message << Colorize.bold(assertion.message.to_s)
  message << "Assertion at:"
  message << clean_backtrace(assertion.backtrace).join("\n")
  message = message.join("\n")

  io.puts(message.tabto(TAB_SIZE))

  #unless backtrace.empty?
  #  io.puts "Assertion at".tabto(TAB_SIZE)
  #  io.puts backtrace.map{|l| l.tabto(TAB_SIZE)}.join("\n")
  #end

  #io.puts "STDERR:".tabto(TAB_SIZE)
  show_captured_output
end

#finish_suite(suite) ⇒ Object

TODO: pending (skip) counts



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/turn/reporters/outline_reporter.rb', line 159

def finish_suite(suite)
  total      = suite.count_tests
  passes     = suite.count_passes
  assertions = suite.count_assertions
  failures   = suite.count_failures
  errors     = suite.count_errors
  skips      = suite.count_skips

  bar = '=' * 78
  # @FIXME: Remove this, since Colorize already take care of colorize?
  if colorize?
    bar = if pass == total then Colorize.green(bar)
          else Colorize.red(bar) end
  end

  # @FIXME: Should we add suite.runtime, instead if this lame time calculations?
  tally = [total, assertions, (Time.new - @time)]

  io.puts bar
  io.puts "  pass: %d,  fail: %d,  error: %d, skip: %d" % [passes, failures, errors, skips]
  io.puts "  total: %d tests with %d assertions in %f seconds" % tally
  io.puts bar
end

#finish_test(test) ⇒ Object



121
122
123
124
# File 'lib/turn/reporters/outline_reporter.rb', line 121

def finish_test(test)
  $stdout = STDOUT
  $stderr = STDERR
end

#pass(message = nil) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/turn/reporters/outline_reporter.rb', line 62

def pass(message=nil)
  io.puts " %s %s" % [ticktock, PASS]

  if message
    message = Colorize.magenta(message)
    message = message.to_s.tabto(TAB_SIZE)
    io.puts(message)
  end
end

#show_captured_outputObject



127
128
129
130
# File 'lib/turn/reporters/outline_reporter.rb', line 127

def show_captured_output
  show_captured_stdout
  #show_captured_stderr
end

#show_captured_stdoutObject



133
134
135
136
137
138
139
140
# File 'lib/turn/reporters/outline_reporter.rb', line 133

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

#skip(exception) ⇒ Object



110
111
112
113
114
115
116
117
118
# File 'lib/turn/reporters/outline_reporter.rb', line 110

def skip(exception)
  io.puts " %s %s" % [ticktock, SKIP]

  message = exception.message

  io.puts(message.tabto(8))

  show_captured_output
end

#start_case(kase) ⇒ Object



38
39
40
# File 'lib/turn/reporters/outline_reporter.rb', line 38

def start_case(kase)
  io.puts(Colorize.bold("#{kase.name}")) if kase.size > 0
end

#start_suite(suite) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/turn/reporters/outline_reporter.rb', line 21

def start_suite(suite)
  @suite  = suite
  @time   = Time.now
  # @FIXME (y8): Why we need to capture stdout and stderr?
  @stdout = StringIO.new
  @stderr = StringIO.new
  #files  = suite.collect{ |s| s.file }.join(' ')
  puts '=' * 78
  if suite.seed
    io.puts "SUITE #{suite.name} (SEED #{suite.seed})"
  else
    io.puts "SUITE #{suite.name}"
  end
  puts '=' * 78
end

#start_test(test) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/turn/reporters/outline_reporter.rb', line 43

def start_test(test)
  #if @file != test.file
  #  @file = test.file
  #  io.puts(test.file)
  #end

  # @FIXME: Should we move naturalized_name to test itself?
  name = naturalized_name(test)

  io.print "    %-57s" % name

  @stdout.rewind
  @stderr.rewind

  $stdout = @stdout
  $stderr = @stderr unless $DEBUG
end