On 10/6/05, joe.yakich / gmail.com <joe.yakich / gmail.com> wrote:
>
> I was hoping to have a drop-in replacement so that existing code would
> only have to have another require/include line rather than changing
> each assert.* call to some custom one.

Here is how you do that:

require 'test/unit'

module MyAssertions
  def assert(bool)
    puts "My custom assert"
    super
  end

  def assert_equal(obj1, obj2)
    puts "My custom assert_equal"
    super
  end
end

class MyTest < Test::Unit::TestCase
  include MyAssertions

  def test_something
    assert(1==1)
    assert_equal(1,1)
  end
end
__END__

The Test::Unit::TestCase class includes the Test::Unit::Assertions
module which has all the assertion methods. As I've shown above you
can create a module with your own assertions that do what you want,
and then when those assertions call super they will use the assertions
in the Test::Unit::Assertions module. As you can see once you've
created your custom module, your test classes only need to include
that module. To make things even easier, I'd recommend creating your
own subclass of Test::Unit::TestCase that includes your assertion
module, then subclass all yours tests from that class.

Ryan