From: nathaniel@... Date: 2003-01-10T10:40:16+09:00 Subject: Re: Adding hooks to TestUnit Tom Clarke [mailto:tom@u2i.com] wrote: > How about this: > > Module Web > Module Testing > add_pre_setup_hook { > # do my initialization > } > end > end > > So that add_pre_setup_hook is a method on TestCase, which > will add one or more hooks (passed as a block) when called - > in this case when the module is included. I've got to mull this over some more, because I'm still not sure it's the best way to go. For instance, here's an easy way to make sure that users don't introduce subtle bugs by forgetting to call #super in #setup: C:\tmp>type b.rb require 'test/unit' module MyTestModule def setup @setup_called = true end def test_setup_called assert(@setup_called, "You need to call super in your setup") end end class TC < Test::Unit::TestCase include MyTestModule def setup end end C:\tmp>ruby b.rb Loaded suite b Started .. Failure!!! test_setup_called(TC) [b.rb:8]: You need to call super in your setup Finished in 0.0 seconds. 1 tests, 1 assertions, 1 failures, 0 errors I've used a test like this with JUnit before, and it works quite well. I know it's not quite as convenient as what you're proposing, and I'm not saying I won't add something like #add_pre_setup_hook in the future (it's on the TODO so I won't forget about it), but I've got to think about it some more first. For now, what I propose above might be the best way for you to do things in your library. BTW, thanks for making testing such an important part of Narf. I love having well-tested and easy-to-test infrastructure on which to base applications. Nathaniel <:((>< + - - | RoleModel Software, Inc. | EQUIP VI