Module: Test::Unit::ExceptionHandler::ClassMethods

Defined in:
lib/test/unit/exception-handler.rb

Instance Method Summary collapse

Instance Method Details

#exception_handler(method_name) ⇒ void #exception_handler {|test, exception| ... } ⇒ void

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

Overloads:

  • #exception_handler(method_name) ⇒ void

    This method returns an undefined value.

    Add an exception handler method.

    Parameters:

    • method_name (Symbol)

      The method name that handles exception raised in tests.

  • #exception_handler {|test, exception| ... } ⇒ void

    This method returns an undefined value.

    Add an exception handler.

    Yields:

    • (test, exception)

      Gives the test and the exception.

    Yield Parameters:

    • test (Test::Unit::TestCase)

      The test where the exception is raised.

    • exception (Exception)

      The exception that is raised in running the test.

    Yield Returns:

    • (Boolean)

      Whether the handler handles the exception or not. The handler must return true if the handler handles test exception, false otherwise.


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/test/unit/exception-handler.rb', line 52

def exception_handler(*method_name_or_handlers, &block)
  if block_given?
    exception_handlers.unshift(block)
  else
    method_name_or_handlers.each do |method_name_or_handler|
      if method_name_or_handler.respond_to?(:call)
        handler = method_name_or_handler
        exception_handlers.unshift(handler)
      else
        method_name = method_name_or_handler
        attribute(:exception_handler, true, {}, method_name)
      end
    end
  end
end

#exception_handlersObject


25
26
27
# File 'lib/test/unit/exception-handler.rb', line 25

def exception_handlers
  ExceptionHandler.exception_handlers
end

#unregister_exception_handler(*method_name_or_handlers) ⇒ Object


68
69
70
71
72
73
74
75
76
77
78
# File 'lib/test/unit/exception-handler.rb', line 68

def unregister_exception_handler(*method_name_or_handlers)
  method_name_or_handlers.each do |method_name_or_handler|
    if method_name_or_handler.respond_to?(:call)
      handler = method_name_or_handler
      exception_handlers.delete(handler)
    else
      method_name = method_name_or_handler
      attribute(:exception_handler, false, {}, method_name)
    end
  end
end