Permalink
Browse files

+ Added MiniTest::Unit.after_tests { ... }

Refactored _run_suites to make wrapping by plugins easier
[git-p4: depot-paths = "//src/minitest/dev/": change = 5926]
  • Loading branch information...
1 parent 40a61d5 commit 9200f3ce5a3ff37d405bec48a91e10b9af23a5c5 @zenspider zenspider committed Oct 27, 2010
Showing with 20 additions and 3 deletions.
  1. +20 −3 lib/minitest/unit.rb
View
23 lib/minitest/unit.rb
@@ -520,6 +520,16 @@ class Unit
@@out = $stdout
##
+ # A simple hook allowing you to run a block of code after the
+ # tests are done. Eg:
+ #
+ # MiniTest::Unit.after_tests { p $debugging_info }
+
+ def self.after_tests
+ at_exit { at_exit { yield } }
+ end
+
+ ##
# Registers MiniTest::Unit to run tests at process exit
def self.autorun
@@ -546,17 +556,20 @@ def self.output= stream
@@out = stream
end
+ ##
+ # Return all plugins' run methods (methods that start with "run_").
+
def self.plugins
@@plugins ||= (["run_tests"] +
public_instance_methods(false).
grep(/^run_/).map { |s| s.to_s }).uniq
end
- def puts *a
+ def puts *a # :nodoc:
@@out.puts(*a)
end
- def print *a
+ def print *a # :nodoc:
@@out.print(*a)
end
@@ -574,7 +587,7 @@ def _run_anything type
sync = @@out.respond_to? :"sync=" # stupid emacs
old_sync, @@out.sync = @@out.sync, true if sync
- results = suites.map { |suite| _run_suite suite, type }
+ results = _run_suites suites, type
@test_count = results.inject(0) { |sum, (tc, ac)| sum + tc }
@assertion_count = results.inject(0) { |sum, (tc, ac)| sum + ac }
@@ -597,6 +610,10 @@ def _run_anything type
status
end
+ def _run_suites suites, type
+ suites.map { |suite| _run_suite suite, type }
+ end
+
def _run_suite suite, type
header = "#{type}_suite_header"
puts send(header, suite) if respond_to? header

0 comments on commit 9200f3c

Please sign in to comment.