From: Josh Cheek Date: 2011-07-29T23:29:32+09:00 Subject: Re: why startup and shutdown is not being called? --bcaec51ba0cde4fd2f04a9361b3b Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jul 29, 2011 at 9:12 AM, Gaurang Shah wrote: > > startup and shutdown method is not being called. And i don't know why?? > any idea guys ???? > > Modules don't work that way. You're defining startup and shutdown on BaseClass' singleton class, which is not pointed to by DemoTest1's singleton class. You should ether define those methods in another module and then extend DemoTest1, like this: module BaseClassClassMethods def startup p "startup" end def shutdown p "shutdown" end end module BaseClassInstanceMethods def setup p "setup" end def teardown p "teardown" end def cleanup p "cleanup" end end require 'rubygems' gem 'test-unit' require 'test/unit' class DemoTest1 < Test::Unit::TestCase include BaseClassInstanceMethods extend BaseClassClassMethods def test_third() puts "third" end end Or you could hook into the inclusion like this: module BaseClass def self.included(klass) klass.instance_eval do def startup p "startup" end def shutdown p "shutdown" end end end def setup p "setup" end def teardown p "teardown" end def cleanup p "cleanup" end end require 'rubygems' gem 'test-unit' require 'test/unit' class DemoTest1 < Test::Unit::TestCase include BaseClass def test_third() puts "third" end end --bcaec51ba0cde4fd2f04a9361b3b--