Class: Tapout::Reporters::RuntimeReporter

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

Constant Summary collapse

PADDING_SIZE =
4
TABSIZE =
4
WIDTH =

TODO: Fix ANSI for this

`tput cols`.to_i - 1
PASS =
" PASS  "
SKIP =
" TODO  "
OMIT =
" SKIP  "
FAIL =
" FAIL  "
ERROR =
" ERROR "
NOMINAL =
[]

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, #todo

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
# File 'lib/tapout/reporters/runtime_reporter.rb', line 115

def error(test)
  stamp_it(test, ERROR, :red)

  message = test['exception']['message']

  puts
  if message && !message.empty?
    puts
    puts message.tabto(TABSIZE)
  end
  puts

  puts backtrace_snippets(test).tabto(TABSIZE)

  print captured_output(test).tabto(TABSIZE)
end

#fail(test) ⇒ Object



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

def fail(test)
  stamp_it(test, FAIL, :red)

  #message = assertion.location[0] + "\n" + assertion.message #.gsub("\n","\n")
  #trace   = MiniTest::filter_backtrace(report[:exception].backtrace).first

  message = test['exception']['message']

  puts
  if message
    puts
    puts message.tabto(TABSIZE)
  end
  puts

  puts backtrace_snippets(test).tabto(TABSIZE)

  print captured_output(test).tabto(TABSIZE)
end

#finish_case(kase) ⇒ Object



138
139
140
141
142
# File 'lib/tapout/reporters/runtime_reporter.rb', line 138

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

#finish_suite(final) ⇒ Object



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

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

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

  time, rate, avg = time_tally(final)

  puts
  puts "Finished in %.6f seconds. %.3f tests per second." % [time, rate]
  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



133
134
135
# File 'lib/tapout/reporters/runtime_reporter.rb', line 133

def finish_test(test)
  puts unless config.minimal?
end

#omit(test) ⇒ Object



89
90
91
# File 'lib/tapout/reporters/runtime_reporter.rb', line 89

def omit(test)
  stamp_it(test, OMIT, :blue) unless config.minimal?
end

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



168
169
170
# File 'lib/tapout/reporters/runtime_reporter.rb', line 168

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

#pad_with_size(str) ⇒ Object (private)



173
174
175
# File 'lib/tapout/reporters/runtime_reporter.rb', line 173

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

#pass(test) ⇒ Object

TODO: Only show if in verbose mode.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tapout/reporters/runtime_reporter.rb', line 68

def pass(test)
  stamp_it(test, PASS, :green) unless config.minimal?

  #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

#skip(test) ⇒ Object



84
85
86
# File 'lib/tapout/reporters/runtime_reporter.rb', line 84

def skip(test)
  stamp_it(test, SKIP, :cyan) #unless config.minimal?
end

#stamp_it(test, type, *color) ⇒ Object (private)



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/tapout/reporters/runtime_reporter.rb', line 180

def stamp_it(test, type, *color)
  @index += 1

  cases  = @case_stack.map{ |k| k['label'] }.join(' ')
  time  = Time.now
  delta = time - @test_time
  #label = test['label']
  label = [cases, test['label']].join(' ').strip

  indexS = @index
  prcntS = " %3s%% " % [@count * 100 / @suite_size]
  ratioS = " #{@count}/#{@suite_size} "
  deltaS = " %.6f " % [time - @test_time]
   timeS = " " + duration(time - @start_time) #time.strftime(' %H:%M:%S.%L ')
   typeS = type.to_s

  width = WIDTH - (ratioS.size + prcntS.size + deltaS.size + timeS.size + indexS.size + typeS.size + 9)

   typeS = typeS.ansi(*color)

  prcntS = prcntS.ansi(*NOMINAL)
  ratioS = ratioS.ansi(*NOMINAL)

  if delta > 30
    delteS = deltaS.ansi(:yellow)
  elsif delta > 60
    deltaS = deltaS.ansi(:red)
  else
    deltaS = deltaS.ansi(*NOMINAL)
  end

  timeS = timeS.ansi(*NOMINAL)

  stuff = [indexS, typeS, label.ansi(:bold), ratioS, prcntS, deltaS, timeS]

  print " %#{@index_pad}d |%s| %-#{width}s %s|%s|%s|%s" % stuff
end

#start_case(kase) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/tapout/reporters/runtime_reporter.rb', line 49

def start_case(kase)
  #return if kase.size == 0  # TODO: Don't have size yet?
  last = @case_stack.pop
  while last
    break if last['level'].to_i <= kase['level'].to_i
    last = @case_stack.pop
  end

  @case_stack << kase
end

#start_suite(suite) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tapout/reporters/runtime_reporter.rb', line 28

def start_suite(suite)
  super(suite)

  @suite  = suite
  @count  = 0
  @index  = 0

  @suite_size = suite['count'].to_i
  @case_stack = []

  # pad for index based on how big the index number will get
  @index_pad = @suite_size.zero? ? '' : @suite_size.to_s.size

  #files = suite['files'].collect{ |s| s.file }.join(' ')

  print "Started Suite (#{@suite_size})" ##{suite.name}"
  print " w/ Seed: #{suite['seed']}" if suite['seed']
  puts
end

#start_test(test) ⇒ Object



61
62
63
64
65
# File 'lib/tapout/reporters/runtime_reporter.rb', line 61

def start_test(test)
  @test_time = Time.now
  @test  = test
  @count = @count + 1
end