Class: Minitest::Test
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Minitest::Runnable
|
Defined in: | lib/minitest/test.rb, lib/minitest/hell.rb |
Overview
Subclass Test to create your own tests. Typically you'll want a Test
subclass per implementation class.
See Assertions
Class Method Summary
-
.i_suck_and_my_tests_are_order_dependent!
Call this at the top of your tests when you absolutely positively need to have ordered tests.
-
.make_my_diffs_pretty!
Make diffs for this
Test
use#pretty_inspect
so that diff in assert_equal can have more details. -
.parallelize_me!
Call this at the top of your tests when you want to run your tests in parallel.
-
.runnable_methods
Returns all instance methods starting with “test_”.
-
.test_order
Defines the order to run tests (:random by default).
Guard - Extended
jruby? | Is this running on jruby? |
maglev? | Is this running on maglev? |
mri? | Is this running on mri? |
osx? | Is this running on macOS? |
rubinius? | Is this running on rubinius? |
windows? | Is this running on windows? |
Runnable - Inherited
.methods_matching | Returns all instance methods matching the pattern |
.run | Responsible for running all runnable methods in a given class, each in its own instance. |
.run_one_method | Runs a single method and has the reporter record the result. |
.runnable_methods | Each subclass of Runnable is responsible for overriding this method to return all runnable methods. |
.runnables | Returns all subclasses of Runnable. |
Instance Attribute Summary
Reportable - Included
Assertions - Included
#skipped? | Was this testcase skipped? Meant for |
Runnable - Inherited
Instance Method Summary
-
#run
Runs a single test with setup/teardown hooks.
Guard - Included
#jruby? | Is this running on jruby? |
#maglev? | Is this running on maglev? |
#mri? | Is this running on mri? |
#osx? | Is this running on macOS? |
#rubinius? | Is this running on rubinius? |
#windows? | Is this running on windows? |
LifecycleHooks - Included
#after_setup | Runs before every test, after setup. |
#after_teardown | Runs after every test, after teardown. |
#before_setup | Runs before every test, before setup. |
#before_teardown | Runs after every test, before teardown. |
#setup | Runs before every test. |
#teardown | Runs after every test. |
Reportable - Included
#location | The location identifier of this test. |
#result_code | Returns “.”, “F”, or “E” based on the result of the run. |
Assertions - Included
#assert | Fails unless |
#assert_empty | Fails unless |
#assert_equal | Fails unless |
#assert_in_delta | For comparing Floats. |
#assert_in_epsilon | For comparing Floats. |
#assert_includes | Fails unless |
#assert_instance_of | Fails unless |
#assert_kind_of | Fails unless |
#assert_match | Fails unless |
#assert_mock | Assert that the mock verifies correctly. |
#assert_nil | Fails unless |
#assert_operator | For testing with binary operators. |
#assert_output | Fails if stdout or stderr do not output the expected results. |
#assert_path_exists | Fails unless |
#assert_predicate | For testing with predicates. |
#assert_raises | Fails unless the block raises one of |
#assert_respond_to | Fails unless |
#assert_same | Fails unless |
#assert_send |
|
#assert_silent | Fails if the block outputs anything to stderr or stdout. |
#assert_throws | Fails unless the block throws |
#capture_io | Captures $stdout and $stderr into strings: |
#capture_subprocess_io | Captures $stdout and $stderr into strings, using Tempfile to ensure that subprocess IO is captured as well. |
#diff | Returns a diff between |
#exception_details | Returns details for exception |
#fail_after | Fails after a given date (in the local time zone). |
#flunk | Fails with |
#message | Returns a proc that will output |
#mu_pp | This returns a human-readable version of |
#mu_pp_for_diff | This returns a diff-able more human-readable version of |
#pass | used for counting assertions. |
#refute | Fails if |
#refute_empty | Fails if |
#refute_equal | Fails if |
#refute_in_delta | For comparing Floats. |
#refute_in_epsilon | For comparing Floats. |
#refute_includes | Fails if |
#refute_instance_of | Fails if |
#refute_kind_of | Fails if |
#refute_match | Fails if |
#refute_nil | Fails if |
#refute_operator | Fails if |
#refute_path_exists | Fails if |
#refute_predicate | For testing with predicates. |
#refute_respond_to | Fails if |
#refute_same | Fails if |
#skip | Skips the current run. |
#skip_until | Skips the current run until a given date (in the local time zone). |
#things_to_diff | Returns things to diff [expect, butwas], or [nil, nil] if nothing to diff. |
Runnable - Inherited
#result_code | Returns a single character string to print based on the result of the run. |
#run | Runs a single method. |
Class Method Details
.i_suck_and_my_tests_are_order_dependent!
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 31
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!
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 44
def self.make_my_diffs_pretty! require "pp" define_method :mu_pp, &:pretty_inspect end
.parallelize_me!
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.
.runnable_methods
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 65
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
.test_order
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
Instance Method Details
#run
Runs a single test with setup/teardown hooks.
# File 'lib/minitest/test.rb', line 92
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 Result.from self # per contract end