Module | MiniTest::Assertions |
In: |
lib/minitest/unit.rb
|
MiniTest Assertions. All assertion methods accept a msg which is printed if the assertion fails.
UNDEFINED | = | Object.new # :nodoc: |
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 floats use assert_in_delta.
See also: MiniTest::Assertions.diff
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
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.
See also: assert_silent
For testing with predicates.
assert_predicate str, :empty?
This is really meant for specs and is front-ended by assert_operator:
str.must_be :empty?
Fails unless the block raises one of exp. Returns the exception matched so you can check the message, attributes, etc.
send_ary is a receiver, message and arguments.
Fails unless the call returns a true value TODO: I should prolly remove this from specs
Fails if the block outputs anything to stderr or stdout.
See also: assert_output
Captures $stdout and $stderr into strings:
out, err = capture_io do warn "You did a bad thing" end assert_match %r%bad%, err
Returns a proc that will output msg along with the default message.
This returns a human-readable version of obj. By default inspect is called. You can override this to use pretty_print if you want.
Fails if +o1+ is not op +o2+. Eg:
refute_operator 1, :>, 2 #=> pass refute_operator 1, :<, 2 #=> fail
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?