Forum: Ruby on Rails Is mock Object the best way to test scheduling system with a

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
F78258e63d2879413ebf4558d74c1a9e?d=identicon&s=25 Kevin Yang (Guest)
on 2007-06-06 13:17
(Received via mailing list)
Hi everyone,
    I hope everyone is doing well.
   I am working on a scheduling system that dealing with a
lot.  It is getting tricky to write test code for the function.

   suppose a function in a model:

   def expired?
        self.expire_time <=

   i was wondering what is the best way to test it.   Or should I say
that I should design the function in the following way (more

    def expired?(time)
         self.expire_time <= time

    then I should use it in the following way :  object.expired?
    it is also easier to write test code.

    Any comments and suggestions will be greatly appreciated :)

82a61255b4090da7d3619f870b0794dc?d=identicon&s=25 James Mead (floehopper)
on 2007-06-06 13:28
(Received via mailing list)
You could use Mocha ( to temporarily stub
the method for the duration of an individual test. Something
like this...

require 'mocha'

def test_me
 specific_time = Time.parse('2007-01-01 06:30:00')
 Time.stubs(:now).returns(specified_time) # => Mon Jan 01 06:30:00 +0000 2007
F78258e63d2879413ebf4558d74c1a9e?d=identicon&s=25 Kevin Yang (Guest)
on 2007-06-06 13:35
(Received via mailing list)
This is genius ~~ how simply the dirty work could be done !

Great thanks to James :)
This topic is locked and can not be replied to.