Rufus-scheduler and automatic test

141 views
Skip to first unread message

gdo

unread,
Feb 22, 2012, 3:54:31 PM2/22/12
to Rufus Ruby
Hello,

I use rufus-scheduler in my program and it's work very fine (thanks
for this gem).

But now, I need to do automatic test and in the code you use Time.now
and I can't control the system date to repeat my test.

Is it possible to replace Time.now by

def Rufus.time_now
if $rufus_time == nil
return Time.now
else
return $rufus_time
end
end

with this code I obtain a fine control on time to repeat my tests.

Best regards

John Mettraux

unread,
Feb 22, 2012, 4:09:52 PM2/22/12
to rufus...@googlegroups.com

On Wed, Feb 22, 2012 at 12:54:31PM -0800, gdo wrote:
>
> But now, I need to do automatic test and in the code you use Time.now
> and I can't control the system date to repeat my test.
>
> Is it possible to replace Time.now by
>
> def Rufus.time_now
> if $rufus_time == nil
> return Time.now
> else
> return $rufus_time
> end
> end
>
> with this code I obtain a fine control on time to repeat my tests.

Hello Guillaume,

why not simply override Time.now at the beginning of your tests?

def Time.now
# return your test time...
end

If you want something a bit more sophisticated:

https://github.com/jtrupiano/timecop

There are other such time stopping gems, but I only remember this one.


Best regards,

--
John Mettraux - http://lambda.io/processi

Reply all
Reply to author
Forward
0 new messages