class Minitest::Test
def self.i_suck_and_my_tests_are_order_dependent!
def self.i_suck_and_my_tests_are_order_dependent! class << self undef_method :test_order if method_defined? :test_order define_method :test_order do :alpha end end end
def self.make_my_diffs_pretty!
def self.make_my_diffs_pretty! require "pp" define_method :mu_pp do |o| o.pretty_inspect end end
def self.parallelize_me!
def self.parallelize_me! include Minitest::Parallel::Test extend Minitest::Parallel::Test::ClassMethods end
def self.runnable_methods
def self.runnable_methods methods = methods_matching(/^test_/) case self.test_order when :random, :parallel then max = methods.size methods.sort.sort_by { rand max } when :alpha, :sorted then methods.sort else raise "Unknown test_order: #{self.test_order.inspect}" end end
def self.test_order
def self.test_order :random end
def capture_exceptions # :nodoc:
def capture_exceptions # :nodoc: yield rescue *PASSTHROUGH_EXCEPTIONS raise rescue Assertion => e self.failures << e rescue Exception => e self.failures << UnexpectedError.new(e) end
def error?
def error? self.failures.any? { |f| UnexpectedError === f } end
def location
def location loc = " [#{self.failure.location}]" unless passed? or error? "#{self.class}##{self.name}#{loc}" end
def marshal_dump # :nodoc:
def marshal_dump # :nodoc: super << self.time end
def marshal_load ary # :nodoc:
def marshal_load ary # :nodoc: self.time = ary.pop super end
def passed?
def passed? not self.failure end
def result_code
def result_code self.failure and self.failure.result_code or "." end
def run
def run with_info_handler do time_it do capture_exceptions do before_setup; setup; after_setup self.send self.name end TEARDOWN_METHODS.each do |hook| capture_exceptions do self.send hook end end end end self # per contract end
def skipped?
def skipped? self.failure and Skip === self.failure end
def test_order # :nodoc:
def test_order # :nodoc: :parallel end
def time_it # :nodoc:
def time_it # :nodoc: t0 = Minitest.clock_time yield ensure self.time = Minitest.clock_time - t0 end
def to_s # :nodoc:
def to_s # :nodoc: return location if passed? and not skipped? failures.map { |failure| "#{failure.result_label}:\n#{self.location}:\n#{failure.message}\n" }.join "\n" end
def with_info_handler &block # :nodoc:
def with_info_handler &block # :nodoc: t0 = Minitest.clock_time handler = lambda do warn "\nCurrent: %s#%s %.2fs" % [self.class, self.name, Minitest.clock_time - t0] end self.class.on_signal "INFO", handler, &block end