Asserts in aggregate objects called by a Test::Unit::TestCase

Thanks for the response Eric. I looked up add_assert but it didn't
really help that much since the aggregate object (SubAssertObj) is in a
diff context then the original TestStuff testcase.

However I did do something similar to your other suggestion. I threw the
validation code in a module and I'm now include'ing in my individual
testcases as needed.

Thanks again.

···

-----Original Message-----
From: Eric Hodel [mailto:drbrain@segment7.net]
Sent: Wednesday, May 10, 2006 10:46 AM
To: ruby-talk ML
Subject: Re: Asserts in aggregate objects called by a
Test::Unit::TestCase

On May 10, 2006, at 10:31 AM, Andrew Tanner wrote:

Howdy Rubyists,

I'm building a framework for automating tests so I've been sinking my
teeth into Test::Unit pretty heavily. Right now I'm trying to
automagically do a bunch of asserts in a sub object called by a
Test::Unit::TestCase subclass similar to something like this...

require "test/unit"

class TestStuff < Test::Unit::TestCase

   def test_stuff
      obj = SubAssertObj.new
      obj.verify_stuff("please_work")
   end

end

class SubAssertObj

    import Test::Unit::Assertions

    def verify_stuff(str)
       assert_equal("please_work", str)
    end

end

Now if the assert_equal fails it throws the
Test::Unit::AssertionFailedError like expected and it reports it very
nicely in the output. However if the assert is successful in the
output
from Test::Unit I get

1 tests, 0 assertions, 0 failures, 0 errors

See add_assertion in Test::Unit::TestCase and Test::Unit::Assertions

How can I get the assertions in the sub object to be reflected in the
report from Test::Unit?

Why not write it like this:

class TestStuff < Test::Unit::TestCase

   def test_stuff
     util_verify_stuff 'please work'
   end

   def util_verify_stuff(str)
     assert_equal 'please work', str
   end

end

And then use subclassing to reuse common functionality?

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com