From: Sean Ross Date: 2005-06-28T05:50:40+09:00 Subject: Re: unit testing singletons "Joe Van Dyk" wrote in message news:c715e640506271106cf2347c@mail.gmail.com... Hi, How can I properly unit test a singleton? I want to reinitialize it on every test method, but since it seems to stick around in memory, I can't seem to ever create a new singleton object. Thanks, Joe Is this what you're looking for? require 'singleton' class YourSingleton attr_accessor :data include Singleton end def YourSingleton.instance_for_testing @__instance__ = new end s = YourSingleton.instance s.data = 1 puts "s.data=>'#{s.data}'" # reinitialize instance t = YourSingleton.instance_for_testing t.data = 2 puts "t.data=>'#{t.data}'" w = YourSingleton.instance puts "w.data=>'#{w.data}'" # old instance puts "s.data=>'#{s.data}'" # output: # # s.data=>'1' # t.data=>'2' # w.data=>'2' # s.data=>'1' #