Class: Mini::Test
Defined Under Namespace
Classes: TestCase
Constant Summary collapse
- VERSION =
"1.2.1"
- @@out =
$stdout
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Test
constructor
A new instance of Test.
- #puke(klass, meth, e) ⇒ Object
-
#run(args) ⇒ Object
Top level driver, controls all output and filtering.
- #run_test_suites(filter = /^test/) ⇒ Object
Constructor Details
#initialize ⇒ Test
Returns a new instance of Test.
317 318 319 320 |
# File 'lib/mini/test.rb', line 317 def initialize @report = [] @errors = @failures = 0 end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
282 283 284 |
# File 'lib/mini/test.rb', line 282 def errors @errors end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
282 283 284 |
# File 'lib/mini/test.rb', line 282 def failures @failures end |
#report ⇒ Object (readonly)
Returns the value of attribute report.
282 283 284 |
# File 'lib/mini/test.rb', line 282 def report @report end |
Class Method Details
.autorun ⇒ Object
287 288 289 290 291 292 293 |
# File 'lib/mini/test.rb', line 287 def self.autorun at_exit { exit_code = Mini::Test.new.run(ARGV) exit exit_code if exit_code } unless @@installed_at_exit @@installed_at_exit = true end |
.output=(stream) ⇒ Object
295 296 297 |
# File 'lib/mini/test.rb', line 295 def self.output= stream @@out = stream end |
Instance Method Details
#puke(klass, meth, e) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/mini/test.rb', line 299 def puke klass, meth, e if Mini::Assertion === e then @failures += 1 loc = e.backtrace.find { |s| s !~ /in .(assert|flunk|pass|fail|raise)/ } loc.sub!(/:in .*$/, '') @report << "Failure:\n#{meth}(#{klass}) [#{loc}]:\n#{e.}\n" 'F' else @errors += 1 bt = Mini::filter_backtrace(e.backtrace).join("\n ") e = "Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.}\n #{bt}\n" @report << e 'E' end end |
#run(args) ⇒ Object
Top level driver, controls all output and filtering.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/mini/test.rb', line 325 def run args filter = if args.first =~ /^(-n|--name)$/ then args.shift arg = args.shift arg =~ /\/(.*)\// ? Regexp.new($1) : arg else /./ # anything - ^test_ already filtered by #tests end @@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted" start = Time.now run_test_suites filter @@out.puts @@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds." @report.each_with_index do |msg, i| @@out.puts "\n%3d) %s" % [i + 1, msg] end @@out.puts format = "%d tests, %d assertions, %d failures, %d errors" @@out.puts format % [@test_count, @assertion_count, failures, errors] return failures + errors if @test_count > 0 # or return nil... end |
#run_test_suites(filter = /^test/) ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/mini/test.rb', line 354 def run_test_suites filter = /^test/ @test_count, @assertion_count = 0, 0 old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync= TestCase.test_suites.each do |suite| suite.test_methods.grep(filter).each do |test| inst = suite.new test inst._assertions = 0 @@out.puts "\n#{test}: " if $DEBUG result = inst.run(self) @@out.print result @@out.puts if $DEBUG @test_count += 1 @assertion_count += inst._assertions end end @@out.sync = old_sync if @@out.respond_to? :sync= [@test_count, @assertion_count] end |