class Minitest::Test

Subclass Test to create your own tests. Typically you’ll want a Test subclass per implementation class.

See Minitest::Assertions

Public Class Methods

i_suck_and_my_tests_are_order_dependent!() click to toggle source

Call this at the top of your tests when you absolutely positively need to have ordered tests. In doing so, you’re admitting that you suck and your tests are weak.

# File minitest-5.25.1/lib/minitest/test.rb, line 35
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
make_my_diffs_pretty!() click to toggle source

Make diffs for this Test use pretty_inspect so that diff in assert_equal can have more details. NOTE: this is much slower than the regular inspect but much more usable for complex objects.

# File minitest-5.25.1/lib/minitest/test.rb, line 48
def self.make_my_diffs_pretty!
  require "pp"

  define_method :mu_pp, &:pretty_inspect
end
parallelize_me!() click to toggle source

Call this at the top of your tests (inside the Minitest::Test subclass or describe block) when you want to run your tests in parallel. In doing so, you’re admitting that you rule and your tests are awesome.

# File minitest-5.25.1/lib/minitest/test.rb, line 60
def self.parallelize_me!
  include Minitest::Parallel::Test
  extend Minitest::Parallel::Test::ClassMethods
end
runnable_methods() click to toggle source

Returns all instance methods starting with “test_”. Based on test_order, the methods are either sorted, randomized (default), or run in parallel.

# File minitest-5.25.1/lib/minitest/test.rb, line 70
def self.runnable_methods
  methods = methods_matching(/^test_/)

  case self.test_order
  when :random, :parallel then
    srand Minitest.seed
    methods.sort.shuffle
  when :alpha, :sorted then
    methods.sort
  else
    raise "Unknown test_order: #{self.test_order.inspect}"
  end
end

Public Instance Methods

run() click to toggle source

Runs a single test with setup/teardown hooks.

# File minitest-5.25.1/lib/minitest/test.rb, line 87
def run
  time_it do
    capture_exceptions do
      SETUP_METHODS.each do |hook|
        self.send hook
      end

      self.send self.name
    end

    TEARDOWN_METHODS.each do |hook|
      capture_exceptions do
        self.send hook
      end
    end
  end

  Result.from self # per contract
end