[rspec-users] Specs of code that use Time.now
court3nay at gmail.com
Tue Feb 13 15:16:58 EST 2007
On 2/13/07, aslak hellesoy <aslak.hellesoy at gmail.com> wrote:
> 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.
Time.stub! and only use should_receive when you're specifically
testing that Time.now is called.
More information about the rspec-users