Вы находитесь на странице: 1из 9

module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

Home
Pages Classes Methods
module
Minitest::Assertions
Methods
::diff
::diff= Minitest Assertions. All assertion methods
#assert accept a msg which is printed if the assertion
#assert_empty
fails.
#assert_equal
#assert_in_delta Protocol: Nearly everything here boils up to
#assert_in_epsilon
assert, which expects to be able to
#assert_includes
#assert_instance_of increment an instance accessor named
#assert_kind_of assertions. This is not provided by
#assert_match Assertions and must be provided by the
#assert_mock
thing including Assertions. See
#assert_nil
#assert_operator Minitest::Runnable for an example.
#assert_output
#assert_predicate
#assert_raises
#assert_respond_to
Public Class Methods
#assert_same
#assert_send
diff()
#assert_silent
#assert_throws
Returns the diff command to use in diff. Tries
#capture_io
#capture_subprocess_io to intelligently figure out what diff to use.
#diff
#exception_details
#flunk diff=(o)
#message
#mu_pp Set the diff command to use in diff.
#mu_pp_for_diff
#pass
#refute
#refute_empty Public Instance Methods
#refute_equal
#refute_in_delta
#refute_in_epsilon assert(test, msg = nil)
#refute_includes
#refute_instance_of Fails unless test is truthy.
#refute_kind_of
#refute_match
#refute_nil assert_empty(obj, msg = nil)
#refute_operator
#refute_predicate Fails unless obj is empty.
#refute_respond_to

1 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

#refute_same assert_equal(exp, act, msg = nil)


#skip
#skipped? Fails unless exp == act printing the
difference between the two, if possible.
If there is no visible difference but the
assertion fails, you should suspect that your
#== is buggy, or your inspect output is
missing crucial details. For nicer structural
diffing, set
Minitest::Test.make_my_diffs_pretty!
For floats use assert_in_delta.
See also: ::diff

assert_in_delta(exp, act, delta =


0.001, msg = nil)
For comparing Floats. Fails unless exp and
act are within delta of each other.

assert_in_delta Math::PI, (22.0 / 7.0), 0.01

assert_in_epsilon(exp, act,
epsilon = 0.001, msg = nil)
For comparing Floats. Fails unless exp and
act have a relative error less than epsilon.

assert_includes(collection, obj,
msg = nil)
Fails unless collection includes obj.

assert_instance_of(cls, obj, msg =


nil)
Fails unless obj is an instance of cls.

2 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

assert_kind_of(cls, obj, msg =


nil)
Fails unless obj is a kind of cls.

assert_match(matcher, obj, msg =


nil)
Fails unless matcher =~ obj.

assert_mock(mock)
Assert that the mock verifies correctly.

assert_nil(obj, msg = nil)


Fails unless obj is nil

assert_operator(o1, op, o2 =
UNDEFINED, msg = nil)
For testing with binary operators. Eg:

assert_operator 5, :<=, 4

assert_output(stdout = nil, stderr


= nil) { || ... }
Fails if stdout or stderr do not output the
expected results. Pass in nil if you don't care
about that streams output. Pass in “” if you
require it to be silent. Pass in a regexp if you
want to pattern match.

assert_output(/hey/) { method_with_output }

NOTE: this uses capture_io, not

3 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

capture_subprocess_io.
See also: assert_silent

assert_predicate(o1, op, msg =


nil)
For testing with predicates. Eg:

assert_predicate str, :empty?

This is really meant for specs and is front-


ended by #assert_operator:

str.must_be :empty?

assert_raises(*exp) { || ... }
Fails unless the block raises one of exp.
Returns the exception matched so you can
check the message, attributes, etc.
exp takes an optional message on the end to
help explain failures and defaults to
StandardError if no exception class is
passed.

assert_respond_to(obj, meth, msg =


nil)
Fails unless obj responds to meth.

assert_same(exp, act, msg = nil)


Fails unless exp and act are equal?

assert_send(send_ary, m = nil)

4 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

send_ary is a receiver, message and


arguments.
Fails unless the call returns a true value

assert_silent() { || ... }
Fails if the block outputs anything to stderr
or stdout.
See also: assert_output

assert_throws(sym, msg = nil) { ||


... }
Fails unless the block throws sym

capture_io() { || ... }
Captures $stdout and $stderr into strings:

out, err = capture_io do


puts "Some info"
warn "You did a bad thing"
end

assert_match %r%info%, out


assert_match %r%bad%, err

NOTE: For efficiency, this method uses


StringIO and does not capture IO for
subprocesses. Use capture_subprocess_io for
that.

capture_subprocess_io() { || ... }
Captures $stdout and $stderr into strings,
using Tempfile to ensure that subprocess IO
is captured as well.

out, err = capture_subprocess_io do

5 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

system "echo Some info"


system "echo You did a bad thing 1>&2"
end

assert_match %r%info%, out


assert_match %r%bad%, err

NOTE: This method is approximately 10x


slower than capture_io so only use it when
you need to test the output of a subprocess.

diff(exp, act)
Returns a diff between exp and act. If there
is no known diff command or if it doesn't
make sense to diff the output (single line,
short output), then it simply returns a basic
comparison between the two.

exception_details(e, msg)
Returns details for exception e

flunk(msg = nil)
Fails with msg

message(msg = nil, ending = nil,


&default)
Returns a proc that will output msg along
with the default message.

mu_pp(obj)
This returns a human-readable version of
obj. By default inspect is called. You can
override this to use pretty_print if you want.

6 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

mu_pp_for_diff(obj)
This returns a diff-able human-readable
version of obj. This differs from the regular
#mu_pp because it expands escaped
newlines and makes hex-values generic (like
object_ids). This uses #mu_pp to do the first
pass and then cleans it up.

pass(_msg = nil)
used for counting assertions

refute(test, msg = nil)


Fails if test is truthy.

refute_empty(obj, msg = nil)


Fails if obj is empty.

refute_equal(exp, act, msg = nil)


Fails if exp == act.
For floats use refute_in_delta.

refute_in_delta(exp, act, delta =


0.001, msg = nil)
For comparing Floats. Fails if exp is within
delta of act.

refute_in_delta Math::PI, (22.0 / 7.0)

refute_in_epsilon(a, b, epsilon =
0.001, msg = nil)

7 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

For comparing Floats. Fails if exp and act


have a relative error less than epsilon.

refute_includes(collection, obj,
msg = nil)
Fails if collection includes obj.

refute_instance_of(cls, obj, msg =


nil)
Fails if obj is an instance of cls.

refute_kind_of(cls, obj, msg =


nil)
Fails if obj is a kind of cls.

refute_match(matcher, obj, msg =


nil)
Fails if matcher =~ obj.

refute_nil(obj, msg = nil)


Fails if obj is nil.

refute_operator(o1, op, o2 =
UNDEFINED, msg = nil)
Fails if o1 is not op o2. Eg:

refute_operator 1, :>, 2 #=> pass


refute_operator 1, :<, 2 #=> fail

refute_predicate(o1, op, msg =


nil)

8 of 9 3/12/19, 8:35 AM
module Minitest::Assertions - minitest-5.11.3 Do... file:///home/engel/Documentos/Respaldo (F)/Teori...

For testing with predicates.

refute_predicate str, :empty?

This is really meant for specs and is front-


ended by #refute_operator:

str.wont_be :empty?

refute_respond_to(obj, meth, msg =


nil)
Fails if obj responds to the message meth.

refute_same(exp, act, msg = nil)


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

skip(msg = nil, bt = caller)


Skips the current run. If run in verbose-
mode, the skipped run gets listed at the end
of the run but doesn't cause a failure exit
code.

skipped?()
Was this testcase skipped? Meant for
teardown.

Validate
Generated by RDoc 6.0.1.
Based on Darkfish by Michael Granger.

9 of 9 3/12/19, 8:35 AM

Оценить