Simon Strandgaard
11/10/2003 2:06:00 PM
On Mon, 10 Nov 2003 13:47:46 +0100, ts wrote:
>>>>>> "S" == Simon Strandgaard <qj5nd7l02@sneakemail.com> writes:
>
> S> Though, now I don't understand why my example didn't work?
>
> Because the new method that you have defined was
>
> def test_x(*a, b)
> end
>
> This give an arity -1, and runit reject these methods it keep only methods
> with a zero arity
>
>
> S> How to make it general so it works for an arbitrary number of arguments ?
>
> You *can't* give an arbitrary number of arguments for a test method
DrainBammage, thats obvious. Thanks.
BTW: I wonder why the last "p instance_methods" doesn't output anything?
--
Simon Strandgaard
server> ruby test_dbg.rb
["test_x"]
Loaded suite test_dbg
Started
.
Finished in 0.002346 seconds.
1 tests, 1 assertions, 0 failures, 0 errors
server> expand -t2 test_dbg.rb
require 'test/unit'
class Object
def self.debug(*args)
p instance_methods(false)
args.each{|method|
name = method.id2name
org = "_debug_"+name
arguments = (method.arity > 0) ? "(*a,&b)" : "(&b)"
code=<<MSG
alias #{org} #{name}
def #{name}#{arguments}
$stdout.puts("before")
#{org}#{arguments}
$stdout.puts("after")
end
private :#{org}
MSG
module_eval code
}
p instance_methods(false) # No output, why ?
end
end
class TestDbg < Test::Unit::TestCase
def test_x
assert_equal(true, true)
end
debug :test_x
end
if $0 == __FILE__
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestDbg)
end
server>