Hi,
(Apologies if this is an obvious question, I’m new to Ruby.)
I’m setting up a unit testing framework for a project here and I’m
loving what I see in Ruby so far. I have one problem though:
I have a large number of test cases which all share common setup and
teardown logic (starting and stopping external processes). To do this
I’ve subclassed Test::Unit::TestCase and all of my project test cases
then derive from this new class. This allows me to override the setup
and teardown methods to do what I want.
This works wonderfully, except that one additional test is always run
and this test always fails saying that “No tests were specified”.
I’m hypothesizing that the unit testing framework is scanning the
ObjectSpace to find all classes that subclass Test::Unit::TestCase and
in addition to the real test cases it’s also finding my intermediate
class, which indeed contains no tests.
I’m currently working around this by also overriding default_test in the
intermediate class and doing nothing, which causes this superfluous test
to pass, but it skews the numbers and I would like a cleaner approach.
It would be nice if the unit testing framework didn’t automatically
insert default_test into the list of tests to be run, but changing the
source (testcase.rb) is an unappealing option because this unit testing
setup will be run by many of the developers here and I don’t want to
have to patch their installations by hand.
I imagine that I could override self.suite in some way to avoid the use
of default_test. I could probably also avoid the use of my intermediate
class altogether by somehow using mixins. (I anticipate that using
mixins to replace existing methods would be tricky.)
Can anyone help guide me through this?
Thanks,
Mike.