Class: TinyTest::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/tinytest.rb

Overview

Make testing reports be abstructive.

Instance Method Summary collapse

Constructor Details

#initialize(out = $stdout) ⇒ Reporter

out is able to be duck-typed as IO.



118
119
120
# File 'lib/tinytest.rb', line 118

def initialize(out = $stdout)
  @f = out
end

Instance Method Details

#blankObject

Put separater blank.



123
124
125
# File 'lib/tinytest.rb', line 123

def blank
  @f.puts
end

#counts_report(n_tests, n_assertions, n_failures, n_errors, n_skips) ⇒ Object

Reports about some test-concerned numbers.



171
172
173
174
175
176
177
178
179
# File 'lib/tinytest.rb', line 171

def counts_report(n_tests, n_assertions, n_failures, n_errors, n_skips)
  @f.puts [
    "#{n_tests} tests",
    "#{n_assertions} assertions",
    "#{n_failures} failures",
    "#{n_errors} errors",
    "#{n_skips} skips"
  ].join(', ')
end

#error_reports(not_succeeded_results) ⇒ Object

Refers to each error report of SuiteResult and puts them with index.



162
163
164
165
166
167
168
# File 'lib/tinytest.rb', line 162

def error_reports(not_succeeded_results)
  not_succeeded_results.each_with_index do |r, i|
    blank
    @f.puts "%3d) #{r.report}" % i.succ
    blank
  end
end

#load_suite(script) ⇒ Object

Announce to start executing some tests of script at first.



128
129
130
131
# File 'lib/tinytest.rb', line 128

def load_suite(script)
  @f.puts "Loaded suite #{script.sub(/\.rb\Z/, '')}"
  @f.puts "Started"
end

#mark_results(results) ⇒ Object

Marks about each SuiteResult.



134
135
136
# File 'lib/tinytest.rb', line 134

def mark_results(results)
  @f.puts results.map{|r| r.char }.join('')
end

#mark_results_with_times(results) ⇒ Object

Marks about each SuiteResult and refers to more details (test-executing-used time).



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/tinytest.rb', line 140

def mark_results_with_times(results)
  unless results.empty?
    vals = results.map{|r|
      ["#{r.suite.inspect}:", r.benchmark.real, r.char]
    }
    w = vals.map{|a| a.first.size }.max
    fmt = "%-#{w}s %.2f sec: %s"
    result_descriptions = vals.map{|a| fmt % a }
  else
    result_descriptions = []
  end
  blank
  @f.puts result_descriptions
  blank
end

#running_times(benchmark) ⇒ Object

After tests are executed, reports about used time.



157
158
159
# File 'lib/tinytest.rb', line 157

def running_times(benchmark)
  @f.puts "Finished in %.6f seconds." % benchmark.real
end