123456789_123456789_123456789_123456789_123456789_

Module: Test::Unit::FailureHandler

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/test/unit/failure.rb

Class Method Summary

Instance Method Summary

Class Method Details

.included(base)

[ GitHub ]

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

[ GitHub ]

  
# 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

#handle_assertion_failed_error(exception) (private)

[ GitHub ]

  
# File 'lib/test/unit/failure.rb', line 123

def handle_assertion_failed_error(exception)
  return false unless exception.is_a?(AssertionFailedError)
  problem_occurred
  add_failure(exception.message, exception.backtrace,
              :expected => exception.expected,
              :actual => exception.actual,
              :inspected_expected => exception.inspected_expected,
              :inspected_actual => exception.inspected_actual,
              :user_message => exception.user_message)
  true
end