From: Jim Weirich Date: 2006-05-25T02:01:21+09:00 Subject: Re: Overriding Time.now Molitor, Stephen L wrote: >> I believe that you can redefine Time.now in the scope where you need >> it without interfering with Test::Unit > > There's only one instance of the Time class object, and any changes you > make to it are in effect 'global'. You can use a technique called "Constant Injection" where you temporarily change the definition of a constant within the scope of a single class. See http://onestepback.org/articles/depinj/classesarejustobjects.html for an example. This allows you to say something like: def test_my_class MyClass.use_class(:Time, MockTime) do mc = MyClass.new # Any calls to Time.now within MyClass will be routed to MockTime.now end # Calls to Time.now are now back to normal. end -- Jim Weirich -- Posted via http://www.ruby-forum.com/.