Class: TapOut::Reporters::TurnReporter

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

Overview

The test report format made famous by Tim Piece and his Turn project.

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

Constant Summary collapse

PASS =

Reporter

"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, #finish_case, #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(doc) ⇒ Object

TODO: TAP-Y/J needs a field for the error class



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tapout/reporters/turn_reporter.rb', line 90

def error(doc)
  exception_class = doc['exception']['class'].to_s
  message         = doc['exception']['message'].to_s.ansi(:bold)
  backtrace       = "Exception `#{exception_class}' at " +
                    clean_backtrace(doc['exception']['backtrace'] || []).join("\n")

  puts("#{ERROR}")
  puts(message.tabto(8))
  puts "STDERR:".tabto(8)
  puts(backtrace.tabto(8))

  show_captured_output
end

#fail(doc) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/tapout/reporters/turn_reporter.rb', line 70

def fail(doc)
  message   = doc['exception']['message'].to_s
  backtrace = clean_backtrace(doc['exception']['backtrace'] || [])

  puts(" #{FAIL}")
  puts message.ansi(:bold).tabto(8)

  unless backtrace.empty?
    label = "Assertion at "
    tabsize = 8
    backtrace1 = label + backtrace.shift
    puts(backtrace1.tabto(tabsize))
    if trace = TapOut.trace
      puts backtrace[0,depth].map{|l| l.tabto(label.length + tabsize) }.join("\n")
    end
  end
  show_captured_output
end

#finish_suite(suite) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/tapout/reporters/turn_reporter.rb', line 143

def finish_suite(suite)
  total   = suite['counts']['total']
  pass    = suite['counts']['pass']
  failure = suite['counts']['fail']
  error   = suite['counts']['error']
  #pass    = total - failure - error

  bar = '=' * 78
  if $ansi
    bar = if pass == total then bar.ansi(:green)
          else bar.ansi(:red) end
  end

  #tally = [total, suite.count_assertions]
  tally = [total]

  puts bar
  puts "  pass: %d,  fail: %d,  error: %d" % [pass, failure, error]
  #puts "  total: %d tests with %d assertions in #{Time.new - @time} seconds" % tally
  puts "  total: %d tests in #{Time.new - @time} seconds" % tally
  puts bar
end

#finish_test(test) ⇒ Object



105
106
107
108
# File 'lib/tapout/reporters/turn_reporter.rb', line 105

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

#pass(doc) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/tapout/reporters/turn_reporter.rb', line 60

def pass(doc)
  puts " #{PASS}"
  #if message
  #  message = Colorize.magenta(message)
  #  message = message.to_s.tabto(8)
  #  puts(message)
  #end
end


172
173
174
# File 'lib/tapout/reporters/turn_reporter.rb', line 172

def print(str)
  @io.print(str)
end

#puts(str) ⇒ Object



167
168
169
# File 'lib/tapout/reporters/turn_reporter.rb', line 167

def puts(str)
  @io.puts(str)
end

#show_captured_outputObject



111
112
113
114
# File 'lib/tapout/reporters/turn_reporter.rb', line 111

def show_captured_output
  show_captured_stdout
  #show_captured_stderr
end

#show_captured_stdoutObject



117
118
119
120
121
122
123
124
# File 'lib/tapout/reporters/turn_reporter.rb', line 117

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

#start_case(kase) ⇒ Object



33
34
35
# File 'lib/tapout/reporters/turn_reporter.rb', line 33

def start_case(kase)
  puts("#{kase['label']}".ansi(:bold))
end

#start_suite(suite) ⇒ Object



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

def start_suite(suite)
  @io     = $stdout
  @suite  = suite
  @time   = Time.now
  @stdout = StringIO.new
  @stderr = StringIO.new
  #files = suite.collect{ |s| s.file }.join(' ')
  puts "LOADED SUITE" # #{suite.name}"
  #puts "Started"
end

#start_test(test) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tapout/reporters/turn_reporter.rb', line 38

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

  name = if @natural
           " #{test['label'].gsub("test_", "").gsub(/_/, " ")}" 
         else
           " #{test['label']}"
         end

  print "    %-69s" % name

  @stdout.rewind
  @stderr.rewind

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