Module MiniTest::Assertions
In: lib/minitest/unit.rb

MiniTest Assertions. All assertion methods accept a msg which is printed if the assertion fails.

Methods

Constants

UNDEFINED = Object.new # :nodoc:

Public Class methods

Returns the diff command to use in diff. Tries to intelligently figure out what diff to use.

Set the diff command to use in diff.

Public Instance methods

Fails unless test is a true value.

Fails unless the block returns a true value.

Fails unless obj is empty.

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

For comparing Floats. Fails unless exp and act have a relative error less than epsilon.

Fails unless collection includes obj.

Fails unless obj is an instance of cls.

Fails unless obj is a kind of cls.

Fails unless exp is =~ act.

Fails unless obj is nil

For testing with binary operators.

  assert_operator 5, :<=, 4

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.

Fails unless obj responds to meth.

Fails unless exp and act are equal?

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

Fails unless the block throws sym

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

Returns details for exception e

Fails with msg

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.

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.

used for counting assertions

Fails if test is a true value

Fails if obj is empty.

Fails if exp == act.

For floats use refute_in_delta.

For comparing Floats. Fails if exp is within delta of act

  refute_in_delta Math::PI, (22.0 / 7.0)

For comparing Floats. Fails if exp and act have a relative error less than epsilon.

Fails if collection includes obj

Fails if obj is an instance of cls

Fails if obj is a kind of cls

Fails if obj is nil.

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?

Fails if obj responds to the message meth.

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

Skips the current test. Gets listed at the end of the run but doesn‘t cause a failure exit code.

[Validate]