Problem
=======

The following wouldn't work:

require 'test/unit'
class TC_foo < Test::Unit::TestCase
	define_method(:test_foo){ assert(true) }
end

since the method would have arity -1 and Test::Unit only accepts methods of 
arity 0.


Patch
=====


--- ruby-1.8.1/lib/test/unit/testcase.rb        2003-11-21 00:18:59.000000000 +0100
+++ ruby-1.8.1.inst/lib/test/unit/testcase.rb   2004-04-29 11:22:01.000000000 +0200
@@ -31,7 +31,9 @@
       # Creates a new instance of the fixture for running the
       # test represented by test_method_name.
       def initialize(test_method_name)
-        unless(respond_to?(test_method_name) && method(test_method_name).arity == 0)
+        unless(respond_to?(test_method_name) and
+               (method(test_method_name).arity == 0 ||
+                method(test_method_name).arity == -1))
           throw :invalid_test
         end
         @method_name = test_method_name

Background
==========

http://rcrchive.net/rcr/RCR/RCR227 addresses this issue, and I believe
this RCR has been de-facto approved:

Thu Mar 18 16:22:38 2004  Yukihiro Matsumoto  <matz / ruby-lang.org>
        [...]

        * eval.c (proc_arity): arity is now defined as number of
          parameters that would not be ignored. i.e. Proc.new{}.arity
          returns zero.  update test suites too.

It is also easy to work around the problem by doing  { || assert(true) }.


Rationale
=========

However, I still believe the patch is meaningful since:
* I see no reason why Test::Unit shouldn't accept methods of arity -1
* it is not immediately obvious that Test::Unit is silently rejecting 
  methods of arity -1; in my case I was getting a 'no test methods defined' 
  error, but one wouldn't realize if most methods where defined normally
  and only a few using define_method
* mandating the use of {|| } means "more work for the most common case"


-- 
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Just go ahead and write your own multitasking multiuser os!
Worked for me all the times.
	-- Linus Torvalds