One caution:  I did what Robert suggested a while back.  It works perfectly, but does wreak havoc with Test::Unit and rake test times reporting.  Tests can appear to finish before they've started, etc.  I ended up creating a CurrentTime class:

class CurrentTime
  @@now = nil

  def now
    @@now || Time.now
  end

  def now=(new_time)
    @@now = new_time
  end
end

I changed my code to use CurrentTime.now instead of Time.now.  Test::Unit, rake and friends still use Time.now, so they don't get messed up.  In my unit test I mock out the time by calling CurrentTime.now=.  Crude but it works.

Steve 

-----Original Message-----
From: Robert MannI [mailto:robmnl / gmail.com] 
Sent: Wednesday, May 24, 2006 9:37 AM
To: ruby-talk ML
Subject: Re: Overriding Time.now

Thanks alot Robert, that'll do it



Rob

On 5/24/06, Robert Dober <robert.dober / gmail.com> wrote:
>
> On 5/24/06, Robert MannI <robmnl / gmail.com> wrote:
> >
> > Hello!
> >
> > I have a unit test where I need to simulate a different system time.
> >
> > Hence I need Time.now to return a different time than now, say, now 
> > + 1 month
> >
> > How can I do this?
> >
> > I tried aliasing Time now, but I don't know how to alias class methods.
> >
> > class Time
> > alias_method 'self.original_now', 'self.now'
> > end
> >
> > How can I alias this --or-- is there any better way to simulate a 
> > different time on calling Time.now?
> >
> >
> > Tips and ideas are greatly appreciated, Rob
>
>
> Hi
>
> class Time
>     class << self
>         alias_method :n, :now
>     end
> end
>
> hope that helps
> Cheers
> Robert
>
>
> --
> Deux choses sont infinies : l'univers et la bóŐise humaine ; en ce qui 
> concerne l'univers, je n'en ai pas acquis la certitude absolue.
>
> - Albert Einstein
>
>