On May 11, 2006, at 1:13 PM, Ryan Leavengood wrote: > On 5/11/06, bpettichord / gmail.com <bpettichord / gmail.com> wrote: >> To recap, your test case should now look >> something like this: >> >> class MyTest < Test::Unit::TestCase >> def setup >> $testcase = self >> # other stuff maybe >> end >> public :add_assertion >> def test_something >> # your actual tests... > > Interesting idea. Here is another possibility: > > require 'test/unit' > > module TestHelper > include Test::Unit::Assertions > > def initialize(test) > @test = test > end > > def add_assertion > @test.send(:add_assertion) > end > end > > class MyTestHelper > include TestHelper > > def test_x > assert(true) > end > end > > class TC_Delegate < Test::Unit::TestCase > def test_delegating > MyTestHelper.new(self).test_x > end > end > __END__ > > Using send gets around the private problem (though that isn't > future-proof.) I think passing in the test is better than using a > global. Plus if you just include the TestHelper module to make use of > this, which results in less duplicate code than your solution. There > is probably an even slicker way to do this... I've never needed to have all this complexity to reuse test methods. Making abstract Test::Unit::TestCase subclasses is much simpler than dispatching to some module. -- Eric Hodel - drbrain / segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com