From: phlip Date: 2008-07-15T20:30:23+09:00 Subject: Re: Is it possible to dynamically extend Test::Unit test cases? David Mitchell wrote: > The test cases run as expected, but now I need to add some new test > cases at run time. Why? Just curious... > What I think I need to do is something like this Try this: class MySuite < Test::Unit::TestCase [:concept_1, :concept_2, :concept_3].each do |thang| define_method "test_#{thang}" do assert_concept thang end end def assert_concept(thang) # now convert the thang symbol to a real thing and test it end end > t.send(:define_method, "test_defined_at_run_time", "") You are trying too hard. define_method is easier than that to call. And note I put most of the processing _outside_ the define_method. Its only job is to construct a test case name and pass in a thang. This helps make assert_concept() more comprehensible. -- Phlip