[rspec-users] Specs of code that use Time.now

Courtenay court3nay at gmail.com
Tue Feb 13 11:15:03 EST 2007

On 2/13/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
> Just trying to spec a Rails model that defaults a valid_until date to
> this time tomorrow.  I've done something similar involving Dates, and
> you can stub the :today method to return something fixed.  But when I
> tried this with Time, I found that RSpec calls Time.now four times
> per spec.

Personally I like to put this in spec_helper

def Time.now

Then all dates are fixed (1 day from now is 2006-12-02 for example).
No clue if this is best practise, works well here though.

More information about the rspec-users mailing list