Class: MiniTest::Unit
- Inherits:
-
Object
- Object
- MiniTest::Unit
- Defined in:
- lib/test/unit.rb
Defined Under Namespace
Classes: TestCase
Constant Summary collapse
- VERSION =
"1.1.0"- @@out =
$stdout
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
- .autotest ⇒ Object
- .location_of_failure(e) ⇒ Object
- .output=(stream) ⇒ Object
- .tests_from(klass) ⇒ Object
Instance Method Summary collapse
- #autotest ⇒ Object
- #errors ⇒ Object
- #failures ⇒ Object
-
#initialize ⇒ Unit
constructor
A new instance of Unit.
- #puke(klass, meth, e) ⇒ Object
- #run_test_suites ⇒ Object
Constructor Details
#initialize ⇒ Unit
Returns a new instance of Unit.
107 108 109 110 |
# File 'lib/test/unit.rb', line 107 def initialize @report = [] @results = {:errors => 0, :failures => 0} end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
71 72 73 |
# File 'lib/test/unit.rb', line 71 def report @report end |
Class Method Details
.autotest ⇒ Object
79 80 81 |
# File 'lib/test/unit.rb', line 79 def self.autotest self.new.autotest end |
.location_of_failure(e) ⇒ Object
87 88 89 90 91 |
# File 'lib/test/unit.rb', line 87 def self.location_of_failure(e) e.backtrace.find { |s| s !~ /in .(assert|flunk)/ }.sub(/:in .*$/, '') end |
.output=(stream) ⇒ Object
75 76 77 |
# File 'lib/test/unit.rb', line 75 def self.output= stream @@out = stream end |
.tests_from(klass) ⇒ Object
83 84 85 |
# File 'lib/test/unit.rb', line 83 def self.tests_from(klass) klass.public_instance_methods(true).grep(/^test/).sort end |
Instance Method Details
#autotest ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/test/unit.rb', line 112 def autotest @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted" = Time.now test_count, assertion_count = run_test_suites @@out.puts @@out.puts "Finished in #{'%.6f' % (Time.now - )} seconds." @report.each_with_index do |msg, i| @@out.puts "\n%3d) %s" % [i + 1, msg] end @@out.puts @@out.puts "%d tests, %d assertions, %d failures, %d errors" % [test_count, assertion_count, failures, errors] return failures + errors end |
#errors ⇒ Object
163 164 165 |
# File 'lib/test/unit.rb', line 163 def errors @results[:errors] end |
#failures ⇒ Object
159 160 161 |
# File 'lib/test/unit.rb', line 159 def failures @results[:failures] end |
#puke(klass, meth, e) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/test/unit.rb', line 93 def puke(klass, meth, e) if MiniTest::Assertion === e then @results[:failures] += 1 loc = self.class.location_of_failure(e) @report << "Failure:\n#{meth}(#{klass}) [#{loc}]:\n#{e.}\n" 'F' else @results[:errors] += 1 bt = filter_backtrace(e.backtrace).join("\n ") @report << "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.}\n #{bt}\n" 'E' end end |
#run_test_suites ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/test/unit.rb', line 131 def run_test_suites test_count, assertion_count = 0, 0 TestCase.test_suites.each do |klass| inst = klass.new inst._assertions = 0 tests = self.class.tests_from(klass) tests.each do |meth| result = '.' begin inst.setup inst.__send__ meth rescue Exception => e result = puke(klass, meth, e) ensure begin inst.teardown rescue Exception => e result = puke(klass, meth, e) end end @@out.print result end test_count += tests.size assertion_count += inst._assertions end [test_count, assertion_count] end |