Feature #4025

Add Assertion class to Core

Added by trans (Thomas Sawyer) almost 10 years ago. Updated about 9 years ago.

Target version:


I notice every test framework has it's own Assertion class (names very such as AssertionFailure, AssertionFailureError, etc.)

It would help interoperability if Ruby had a base exception they all could depend upon. Essentially:

class Assertion < Exception; end

This comes from MiniTest, just taken out of the MiniTest namespace.

Having a common base class would allow developers to more easily write test utility libraries that could be used by a variety of test frameworks.


Updated by naruse (Yui NARUSE) almost 10 years ago

  • Status changed from Open to Rejected

This feature needs at least consensus among test frame work authors.
And it needs more use cases.
Your proposal prevents to define Assertion class it inherits other than Exception class.

Updated by trans (Thomas Sawyer) about 9 years ago

Pretty sure Assertion has to be subclass of Exception, because the way test runners work is to use #rescue to catch Assertion failure and other exceptions. Test framework developers can still subclass it for their own specific purposes, e.g. original TestUnit library could do:

module Test
  module Unit
    class Failure < Assertion

An alternative is to define methods Exception#assertion? and Exception#set_assertion(boolean). Then test framework developers can use that to differentiate assertions from other errors.

Also available in: Atom PDF