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

aslak hellesoy aslak.hellesoy at gmail.com
Tue Feb 13 14:20:36 EST 2007

On 2/13/07, Courtenay <court3nay at gmail.com> wrote:
> 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
>   Time.local(2006,12,01,0,0,0)
> end
> 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.

There are no best practices.
But this seems like a good practice.

> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list