diff options
Diffstat (limited to 'test/mauve_time.rb')
-rw-r--r-- | test/mauve_time.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/mauve_time.rb b/test/mauve_time.rb new file mode 100644 index 0000000..d8c57a7 --- /dev/null +++ b/test/mauve_time.rb @@ -0,0 +1,38 @@ +require 'logger' +require 'time' + +module Mauve + # A fake Time, which we use in testing. Time#now returns the same value every + # time, unless we call Time#advance which alters the value of 'now' by a + # given number of seconds. There is a simple pass-through for other methods. + # + class Time + class << self + def reset_to_midnight + @now = Time.parse("00:00") + Log.debug "Test time reset to #{@now}" + end + + def now + reset_to_midnight unless @now + @now + end + + def advance(seconds) + @now += seconds + Log.debug "Test time advanced by #{seconds} to #{@now}, kicking Mauve::Timers" + Timers.restart_and_then_wait_until_idle + @now + end + + def at(*a) + ::Time.at(*a) + end + + def parse(*a) + ::Time.parse(*a) + end + end + end +end + |