Module: Test::Unit::FailureHandler

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



81
82
83
# File 'lib/test/unit/failure.rb', line 81

def included(base)
  base.exception_handler(:handle_assertion_failed_error)
end

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.



112
113
114
115
116
117
118
119
120
# File 'lib/test/unit/failure.rb', line 112

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