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)
TODO =
"TODO".ansi(:magenta)

Constants inherited from Abstract

Abstract::INTERNALS

Instance Method Summary collapse

Methods inherited from Abstract

#<<, #backtrace, #backtrace_snippets, #backtrace_snippets_chain, #captured_output, #captured_output?, #captured_stderr, #captured_stderr?, #captured_stdout, #captured_stdout?, #clean_backtrace, #code_snippet, #complete_cases, #config, #count_tally, #duration, #exit_code, #finalize, #finish_case, #finish_test, #format_snippet_array, #handle, inherited, #initialize, #note, #omit, #parse_backtrace, #parse_source_location, #source, #tally, #tally_message, #time_tally

Constructor Details

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

Instance Method Details

#error(doc) ⇒ Object



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

def error(doc)
  exception_class = doc['exception']['class'].to_s
  message         = doc['exception']['message'].to_s.ansi(:bold)

  backtrace       = clean_backtrace(doc['exception']['backtrace'] || [])
  depth           = config.trace || backtrace.size
  backtrace       = "Exception `#{exception_class}' at " + backtrace[0,depth].join("\n")

  puts("#{ERROR}")
  puts(message.tabto(8))
  puts(captured_output(doc).strip.tabto(8)) if captured_output?(doc)
  puts(backtrace.strip.tabto(8))
end

#fail(doc) ⇒ Object



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

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

  puts(" #{FAIL}")
  puts message.ansi(:bold).tabto(8)
  puts(captured_output(doc).strip.tabto(8)) if captured_output?(doc)
  unless backtrace.empty?
    label = "Assertion at "
    tabsize = 8
    str = (label + backtrace.shift).tabto(tabsize)
    str << backtrace[0,depth].map{|l| l.tabto(label.length + tabsize) }.join("\n")
    #puts(backtrace1.tabto(tabsize))
    puts str.rstrip
  end
end

#finish_suite(suite) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/tapout/reporters/turn_reporter.rb', line 117

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

#pass(doc) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/tapout/reporters/turn_reporter.rb', line 53

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

#start_case(testcase) ⇒ Object



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

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

#start_suite(suite) ⇒ Object



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

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

#start_test(test) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tapout/reporters/turn_reporter.rb', line 37

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
end

#todo(doc) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/tapout/reporters/turn_reporter.rb', line 63

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