From: Brian Adkins Date: 2007-10-12T16:25:03+09:00 Subject: Re: Child < Parent < Test::Unit::TestCase On Oct 12, 2:48 am, Brian Adkins wrote: > On Oct 11, 11:49 pm, George wrote: > > > On 10/12/07, Brian Adkins wrote: > > > Is there a way to instruct Test::Unit to not attempt to run tests in > > > intermediate classes in the hierarchy? > > > Hi Brian, > > > I don't know if it's advisable or not, but one way is to undefine > > `default_test'. > > > require 'test/unit' > > > class AbstractTestCase < Test::Unit::TestCase > > undef_method :default_test > > end > > Thanks! I just looked through testcase.rb, and your suggestion seems > to be exactly what I was asking for. I'm satisfied with the mixin > approach for my current scenario, but it's nice to know I have an > option for inheritance if the need arises. > > Another option is to just hide the class from ObjectSpace :) I did > some experimenting for the heck of it and came up with the following. > It's just a hack for fun, but can anyone come up with a better way of > passing in the class to be hidden to the redefined each_object method > besides the ugly $cloaked global variable? The fact that the > definition is being evaluated in the scope of the metaclass for > ObjectSpace kind of complicates things. > > require "test/unit" > Using a Module class variable helps a bit, but it still doesn't feel right. Of course, that's likely because it's way too late and my brain shut off a couple hours ago :( class Module def hide_class Module.cloaked << self end def Module.cloaked @@cloaked ||= [] end end class << ObjectSpace alias orig_each_object each_object def each_object(klass) ObjectSpace.orig_each_object(klass) do |obj| yield obj if !Module.cloaked.include?(obj) end end end > > class ParentTest < Test::Unit::TestCase > hide_class > > def setup > puts 'setup called' > end > > def teardown > puts 'teardown called' > end > end