S
Simon Strandgaard
I want to overload a testcase method with debug-enabling wrapper.
But it doesn't seems like my Object#debug method gets called at all.
Any ideas how to do this ?
--
Simon Strandgaard
server> ruby test_dbg.rb
Loaded suite TestDbg
Started
F
Finished in 0.008819 seconds.
1) Failure:
default_test(TestDbg) [test_dbg.rb:31]:
No tests were specified.
1 tests, 1 assertions, 1 failures, 0 errors
server> expand -t2 test_dbg.rb
require 'test/unit'
class Object
def self.debug(*args)
args.each{|method|
name = method.id2name
org = "_debug_"+name
code=<<MSG
alias #{org} #{name}
def #{name}(*a,&b)
$stdout.puts("before")
#{org}(*a,&b)
$stdout.puts("after")
end
private :#{org}
MSG
module_eval code
}
end
end
class TestDbg < Test::Unit::TestCase
def test_x
assert_equal(true, true)
end
debug :test_x # uncomment me, and it works!
end
if $0 == __FILE__
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestDbg)
end
server>
But it doesn't seems like my Object#debug method gets called at all.
Any ideas how to do this ?
--
Simon Strandgaard
server> ruby test_dbg.rb
Loaded suite TestDbg
Started
F
Finished in 0.008819 seconds.
1) Failure:
default_test(TestDbg) [test_dbg.rb:31]:
No tests were specified.
1 tests, 1 assertions, 1 failures, 0 errors
server> expand -t2 test_dbg.rb
require 'test/unit'
class Object
def self.debug(*args)
args.each{|method|
name = method.id2name
org = "_debug_"+name
code=<<MSG
alias #{org} #{name}
def #{name}(*a,&b)
$stdout.puts("before")
#{org}(*a,&b)
$stdout.puts("after")
end
private :#{org}
MSG
module_eval code
}
end
end
class TestDbg < Test::Unit::TestCase
def test_x
assert_equal(true, true)
end
debug :test_x # uncomment me, and it works!
end
if $0 == __FILE__
require 'test/unit/ui/console/testrunner'
Test::Unit::UI::Console::TestRunner.run(TestDbg)
end
server>