class Minitest::Test - minitest-5.0.7 Documentation

# class Minitest::Test

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

See Minitest::Assertions

### Attributes

time[RW]

The time it took to run this test.

### 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 lib/minitest/test.rb, line 22
    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 lib/minitest/test.rb, line 35
    def self.make_my_diffs_pretty!
      require "pp"

      define_method :mu_pp do |o|
        o.pretty_inspect
      end
    end

old_test_order()
Alias for: test_order
parallelize_me!() click to toggle source

Call this at the top of your tests when you want to run your tests in parallel. In doing so, you’re admitting that you rule and your tests are awesome.

    # File lib/minitest/test.rb, line 48
    def self.parallelize_me!
      require "minitest/parallel_each"

      class << self
        undef_method :test_order if method_defined? :test_order
        define_method :test_order do :parallel end
      end
    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 lib/minitest/test.rb, line 62
    def self.runnable_methods
      methods = methods_matching(/^test_/)

      case self.test_order
      when :parallel
        max = methods.size
        ParallelEach.new methods.sort.sort_by { rand max }
      when :random 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

test_order() click to toggle source

Defines the order to run tests (:random by default). Override this or use a convenience method to change it for your tests.

    # File lib/minitest/test.rb, line 83
    def self.test_order
      :random
    end

Also aliased as: old_test_order

### Public Instance Methods

capture_io(&b) click to toggle source

    # File lib/minitest/parallel_each.rb, line 73
    def capture_io(&b)
      Test.synchronize do
        simple_capture_io(&b)
      end
    end

Also aliased as: simple_capture_io
capture_subprocess_io(&b) click to toggle source

    # File lib/minitest/parallel_each.rb, line 81
    def capture_subprocess_io(&b)
      Test.synchronize do
        simple_capture_subprocess_io(&b)
      end
    end

Also aliased as: simple_capture_subprocess_io
error?() click to toggle source

Did this run error?

    # File lib/minitest/test.rb, line 221
    def error?
      self.failures.any? { |f| UnexpectedError === f }
    end

location() click to toggle source

The location identifier of this test.

    # File lib/minitest/test.rb, line 228
    def location
      loc = " [#{self.failure.location}]" unless passed? or error?
      "#{self.class}##{self.name}#{loc}"
    end

passed?() click to toggle source

Did this run pass?

Note: skipped runs are not considered passing, but they don’t cause the process to exit non-zero.

    # File lib/minitest/test.rb, line 239
    def passed?
      not self.failure
    end

result_code() click to toggle source

Returns “.”, “F”, or “E” based on the result of the run.

    # File lib/minitest/test.rb, line 246
    def result_code
      self.failure and self.failure.result_code or "."
    end

run() click to toggle source

Runs a single test with setup/teardown hooks.

    # File lib/minitest/test.rb, line 104
    def run
      with_info_handler do
        time_it do
          capture_exceptions do
            before_setup; setup; after_setup

            self.send self.name
          end

          %w{ before_teardown teardown after_teardown }.each do |hook|
            capture_exceptions do
              self.send hook
            end
          end
        end
      end

      self # per contract
    end

simple_capture_io(&b)
Alias for: capture_io
simple_capture_subprocess_io(&b)
Alias for: capture_subprocess_io
skipped?() click to toggle source

Was this run skipped?

    # File lib/minitest/test.rb, line 253
    def skipped?
      self.failure and Skip === self.failure
    end