Module: Test::Unit::FailureHandler

Included in:
TestCase
Defined in:
lib/test/unit/failure.rb,
lib/test/unit/failure.rb

Instance Method Summary collapse

Instance Method Details

#add_failure(message, backtrace, options = {}) ⇒ void

This method returns an undefined value.

Report a failure.

This is a public API for developers who extend test-unit.

Parameters:

  • message (String)

    The description about the failure.

  • backtrace (Array<String>)

    The backtrace for the failure.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :expected (Object)

    The expected value of the assertion.

  • :actual (Object)

    The actual value of the assertion.

  • :inspected_expected (String)

    The inspected expected value of the assertion. It is used for diff between expected and actual of the failure.

  • :inspected_actual (String)

    The inspected actual value of the assertion. It is used for diff between expected and actual of the failure.

  • :user_message (String)

    The message of the assertion from user.

  • :method_name (String) — default: @method_name

    The method name of the test.

  • :source_location (Array<String, Integer>)

    The location where the test is defined. It is the same format as Proc#source_location. That is, it’s an array of path and and line number where the test definition is started.



106
107
108
109
110
111
112
113
114
# File 'lib/test/unit/failure.rb', line 106

def add_failure(message, backtrace, options={})
  default_options = {
    :method_name => @method_name,
    :source_location => self[:source_location],
  }
  failure = Failure.new(name, filter_backtrace(backtrace), message,
                        default_options.merge(options))
  current_result.add_failure(failure)
end