Class: Tapout::Reporters::PrettyReporter

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

Overview

Pretty Reporter (by Paydro)

Constant Summary collapse

PADDING_SIZE =
4
PASS =
" PASS".ansi(*Tapout.config.pass)
TODO =
" TODO".ansi(*Tapout.config.todo)
OMIT =
" OMIT".ansi(*Tapout.config.omit)
FAIL =
" FAIL".ansi(*Tapout.config.fail)
ERROR =
"ERROR".ansi(*Tapout.config.error)

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, #format_snippet_array, #handle, inherited, #initialize, #note, #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(test) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/tapout/reporters/pretty_reporter.rb', line 115

def error(test)
  label = test['label'].to_s.ansi(*config.highlight)

  print pad_with_size("#{ERROR}")
  print " #{label}"
  print " (%.2fs) " % (Time.now - @test_time)

  message = test['exception']['message'].to_s

  tabsize = 10

  puts
  puts message.tabto(tabsize) unless message.empty?
  puts backtrace_snippets(test).tabto(tabsize)

  print captured_output(test).tabto(tabsize)
end

#fail(test) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tapout/reporters/pretty_reporter.rb', line 96

def fail(test)
  label = test['label'].to_s.ansi(*config.highlight)

  print pad_with_size("#{FAIL}")
  print " #{label}"
  print " (%.2fs) " % (Time.now - @test_time)

  message = test['exception']['message'].to_s

  tabsize = 10

  puts
  puts message.tabto(tabsize)
  puts backtrace_snippets(test).tabto(tabsize)

  print captured_output(test).tabto(tabsize)
end

#finish_case(kase) ⇒ Object



143
144
145
146
147
# File 'lib/tapout/reporters/pretty_reporter.rb', line 143

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

#finish_suite(final) ⇒ Object



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

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

  total, pass, fail, error, todo, omit = count_tally(final)

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

  print "%d tests: " % total
  #print "%d assertions, " % suite.count_assertions
  print ("%d failures" % fail).ansi(*config.fail)   + ', '
  print ("%d errors"   % error).ansi(*config.error) + ', '
  print ("%d pending"  % todo).ansi(*config.todo)   + ', '
  print ("%d omitted"  % omit).ansi(*config.omit)
  puts
end

#finish_test(test) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/tapout/reporters/pretty_reporter.rb', line 134

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

#omit(test) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/tapout/reporters/pretty_reporter.rb', line 85

def omit(test)
  return if config.minimal?

  label = test['label'].to_s.ansi(*config.highlight)

  print pad_with_size("#{OMIT}")
  print " #{label}"
  print " (%.2fs) " % (Time.now - @test_time)
end

#pad(str, size = PADDING_SIZE) ⇒ Object (private)



171
172
173
# File 'lib/tapout/reporters/pretty_reporter.rb', line 171

def pad(str, size=PADDING_SIZE)
  " " * size + str
end

#pad_with_size(str) ⇒ Object (private)



176
177
178
# File 'lib/tapout/reporters/pretty_reporter.rb', line 176

def pad_with_size(str)
  " " * (18 - str.size) + str
end

#pass(test) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tapout/reporters/pretty_reporter.rb', line 54

def pass(test)
  return if config.minimal?

  label = test['label'].to_s.ansi(*config.highlight)

  print pad_with_size("#{PASS}")
  print " #{label}"
  print " (%.2fs) " % (Time.now - @test_time)

  #if message
  #  message = test['source'].ansi(:magenta)
  #  message = message.to_s.tabto(10)
  #  puts(message)
  #end

  # TODO: Is there any reason to show captured output for passing test?
  #if captured_output?(test)
  #  puts captured_output(test).tabto(tabsize)
  #end
end

#start_case(kase) ⇒ Object



32
33
34
35
36
# File 'lib/tapout/reporters/pretty_reporter.rb', line 32

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

#start_suite(suite) ⇒ Object



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

def start_suite(suite)
  super(suite)
  @suite  = suite
  #files = suite.collect{ |s| s.file }.join(' ')
  print "Running Suite"  #{suite.name}
  print " w/ Seed: #{suite['seed']}" if suite['seed']
  puts
end

#start_test(test) ⇒ Object



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

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

#todo(test) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/tapout/reporters/pretty_reporter.rb', line 76

def todo(test)
  label = test['label'].to_s.ansi(*config.highlight)

  print pad_with_size("#{TODO}")
  print " #{label}"
  print " (%.2fs) " % (Time.now - @test_time)
end