123456789_123456789_123456789_123456789_123456789_

Class: Minitest::Spec

Relationships & Source Files
Namespace Children
Modules:
DSL
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, DSL, Test, Guard, Runnable
Instance Chain:
Inherits: Minitest::Test
Defined in: lib/minitest/spec.rb

Overview

Spec – The faster, better, less-magical spec framework!

For a list of expectations, see Expectations.

Constant Summary

Runnable - Inherited

SIGNALS

Reportable - Included

BASE_DIR

Assertions - Included

UNDEFINED

Test - Inherited

PASSTHROUGH_EXCEPTIONS, SETUP_METHODS, TEARDOWN_METHODS

Class Attribute Summary

DSL - Extended

Test - Inherited

Class Method Summary

DSL - Extended

after

Define an ‘after’ action.

before

Define a ‘before’ action.

inspect

Alias for DSL#name.

it

Define an expectation with name desc.

let

Essentially, define an accessor for name with block.

register_spec_type

Register a new type of spec that matches the spec’s description.

spec_type

Figure out the spec class to use based on a spec’s description.

specify

Alias for DSL#it.

subject

Another lazy man’s accessor generator.

to_s

Alias for DSL#name.

children, create, describe_stack, name, nuke_test_methods!

Test - Inherited

.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 (inside the Test subclass or describe block) when you want to run your tests in parallel.

.runnable_methods

Returns all instance methods starting with “test_”.

Guard - Extended

jruby?

Is this running on jruby?

mri?

Is this running on mri?

osx?

Is this running on macOS?

windows?

Is this running on windows?

Runnable - Inherited

.filter_runnable_methods

Returns an array of filtered runnable_methods.

.methods_matching

Returns all instance methods matching the pattern re.

.run

Runs a single method and has the reporter record the result.

.run_order

Defines the order to run tests (:random by default).

.run_suite

Responsible for running all runnable methods in a given class, each in its own instance.

.runnable_methods

Each subclass of Runnable is responsible for overriding this method to return all runnable methods.

.runnables

Returns all subclasses of Runnable.

.inherited, .new, .on_signal, .reset, .with_info_handler

Instance Attribute Summary

Assertions - Included

#skipped?

Was this testcase skipped? Meant for #teardown.

Reportable - Included

#error?

Did this run error?

#passed?

Did this run pass?

#skipped?

Was this run skipped?

Runnable - Inherited

#assertions

Number of assertions executed in this run.

#failures

An assertion raised during the run, if any.

#metadata

Metadata you attach to the test results that get sent to the reporter.

#metadata=

Sets metadata, mainly used for Result.from.

#metadata?

Returns true if metadata exists.

#name

Name of the run.

#name=

Set the name of the run.

#passed?

Did this run pass?

#skipped?

Was this run skipped? See #passed? for more information.

#time

The time it took to run.

Instance Method Summary

Test - Inherited

#run

Runs a single test with setup/teardown hooks.

#capture_exceptions

LifecycleHooks.

#neuter_exception, #new_exception, #sanitize_exception

Guard - Included

#jruby?

Is this running on jruby?

#mri?

Is this running on mri?

#osx?

Is this running on macOS?

#windows?

Is this running on windows?

Test::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.

Assertions - Included

#assert

Fails unless test is truthy.

#assert_empty

Fails unless obj is empty.

#assert_equal

Fails unless exp == act printing the difference between the two, if possible.

#assert_in_delta

For comparing Floats.

#assert_in_epsilon

For comparing Floats.

#assert_includes

Fails unless collection includes obj.

#assert_instance_of

Fails unless obj is an instance of cls.

#assert_kind_of

Fails unless obj is a kind of cls.

#assert_match

Fails unless matcher =~ obj.

#assert_nil

Fails unless obj is nil.

#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 path exists.

#assert_pattern

For testing with pattern matching (only supported with Ruby 3.0 and later).

#assert_predicate

For testing with predicates.

#assert_raises

Fails unless the block raises one of exp.

#assert_respond_to

Fails unless obj responds to meth.

#assert_same

Fails unless exp and act are #equal?

#assert_silent

Fails if the block outputs anything to stderr or stdout.

#assert_throws

Fails unless the block throws sym

#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 exp and act.

#exception_details

Returns details for exception e.

#fail_after

Fails after a given date (in the local time zone).

#flunk

Fails with msg.

#message

Returns a proc that delays generation of an output message.

#mu_pp

This returns a human-readable version of obj.

#mu_pp_for_diff

This returns a diff-able more human-readable version of obj.

#pass

used for counting assertions.

#refute

Fails if test is truthy.

#refute_empty

Fails if obj is empty.

#refute_equal

Fails if exp == act.

#refute_in_delta

For comparing Floats.

#refute_in_epsilon

For comparing Floats.

#refute_includes

Fails if obj includes sub.

#refute_instance_of

Fails if obj is an instance of cls.

#refute_kind_of

Fails if obj is a kind of cls.

#refute_match

Fails if matcher =~ obj.

#refute_nil

Fails if obj is nil.

#refute_operator

Fails if o1 is not op o2.

#refute_path_exists

Fails if path exists.

#refute_pattern

For testing with pattern matching (only supported with Ruby 3.0 and later).

#refute_predicate

For testing with predicates.

#refute_respond_to

Fails if obj responds to the message meth.

#refute_same

Fails if exp is the same (by object identity) as act.

#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.

#_synchronize, #_where

Reportable - Included

#location

The location identifier of this test.

#result_code

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

#class_name

Runnable - Inherited

#result_code

Returns a single character string to print based on the result of the run.

#run

Runs a single method.

#failure, #time_it

Constructor Details

This class inherits a constructor from Minitest::Runnable