On Fri, Jan 30, 2009 at 9:05 AM, Mark Wilden <m...@mwilden.com> wrote: > On Fri, Jan 30, 2009 at 7:38 AM, David Chelimsky <dchelim...@gmail.com> > wrote: >> >> On Fri, Jan 30, 2009 at 9:17 AM, Mark Wilden <m...@mwilden.com> wrote: >> > Avdi Grimm wrote a blog post about why he doesn't stub Time.now and >> > instead >> > always injects a clock into his objects. I disagreed, but I can't seem >> > to >> > find the article now. >> >> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/297660 > > Yeah, I saw that, but he laid out his case in greater depth in a blog post > (i know because I posted a comment disagreeing with it!). > > The interesting thing is that Avdi says that stubbing Time.now has broken > some of his tests in the past because of other code (like RSpec) that calls > it. I can't say I've ever run into that myself, but it bears keeping in > mind.
I think that using a custom Clock class can be very useful. However, it can cause confusion in Rails apps, because AR uses Time.now for created_at and updated_at. You'd have to keep specific track of when you meant to use Clock and when you wanted to control Time, and to me it's just not worth it. Pat _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users