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. Pass in a regexp if you want to pattern match.
NOTE: this uses capture_io, not capture_subprocess_io.
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 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.
Captures $stdout and $stderr into strings, using Tempfile to ensure that subprocess IO is captured as well.
out, err = capture_subprocess_io do 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.
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?