[rspec-users] Specs of code that use Time.now
cwdinfo at gmail.com
Tue Feb 13 14:04:30 EST 2007
Why not try this in the applicable spec:
the_time = Time.local(2006,12,01,0,0,0)
Will this break other stuff?
On Feb 13, 2007, at 10:22 AM, Courtenay wrote:
> On 2/13/07, Ashley Moran <work at ashleymoran.me.uk> wrote:
>> On 13 Feb 2007, at 16:15, Courtenay wrote:
>>> 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.
>> Does this not interfere with RSpec? I noticed it calling Time.now
>> four times without any code on my part. I suppose something has to
>> give though
> Try this:
> class Foo
> class Time < ::Time
> def self.now
> def test_local
> f = Foo.new
> => "Sun Oct 01 00:00:00 -0700 2006"
> => Tue Feb 13 10:14:03 -0800 2007
> So, just make a new subclass of your model called Time that inherits
> from ::Time but overrides the .now to fix the date, and it shouldn't
> be that much of a problem :)
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users