From: Pete Yandell Date: 2006-05-30T09:13:36+09:00 Subject: Re: Overriding Time.now Following up a slightly old thread here, but I've taken a hybrid approach to a couple already suggested and it seems to work well: class Time @@now = nil def self.now=(time) @@now = time end def self.forced_now @@now || unforced_now end class << self alias_method :unforced_now, :now alias_method :now, :forced_now end end Then, in my test I can simply do Time.now = whatever. As long as I put a Time.now = nil in my teardown, it doesn't seem to mess up the test timings. (Note that I'm doing this in Rails, so your mileage may vary.) It's important that the Time.now = nil goes in the teardown, rather than in the test itself, to ensure that it runs even if a test fails. Cheers, Pete Yandell http://9cays.com/