The primary function of my rails app compares database date values to the current date. In order to test this functionality, I need to simulate time passing. I currently roll back date fields to trigger certain processes. This becomes increasingly tedious as my application becomes more complex. I would love to artificially advance ActiveRecord datetime during my test to more naturally simulate the passage of time instead of tricking every field in my database into believing it. Anyone ever done this? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Peter, On Jan 15, 2008 7:50 PM, Peter Marks <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> The primary function of my rails app compares database date values to > the current date. In order to test this functionality, I need to > simulate time passing. I currently roll back date fields to trigger > certain processes. This becomes increasingly tedious as my application > becomes more complex. I would love to artificially advance ActiveRecord > datetime during my test to more naturally simulate the passage of time > instead of tricking every field in my database into believing it. Anyone > ever done this?I wrote an extension to Time to support exactly this sort of testing: http://geeksomnia.com/2007/11/07/timetravel_to Time.travel_to(1.week.from_now) do # mess with some objects end I''ve never pluginized it, but if it meets your needs it should be pretty easy for you to integrate. :) ~ j. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
John Barnette wrote:> Hi Peter, > > I wrote an extension to Time to support exactly this sort of testing: > http://geeksomnia.com/2007/11/07/timetravel_to > > Time.travel_to(1.week.from_now) do > # mess with some objects > end > > I''ve never pluginized it, but if it meets your needs it should be > pretty easy for you to integrate. :) > > ~ j.John - This looks awesome. I shall play around with this and let you know how it goes. Muchos Gracias! Peter -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/15/08, Peter Marks <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > The primary function of my rails app compares database date values to > the current date. In order to test this functionality, I need to > simulate time passing. I currently roll back date fields to trigger > certain processes. This becomes increasingly tedious as my application > becomes more complex. I would love to artificially advance ActiveRecord > datetime during my test to more naturally simulate the passage of time > instead of tricking every field in my database into believing it. Anyone > ever done this?Six months or so ago, I did it this way http://talklikeaduck.denhaven2.com/articles/2007/07/18/time-flies-while-youre-having-fun-testing Today, I''d probably use some form of stub or mock, probably what''s built into RSpec. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick Denatale wrote:> Six months or so ago, I did it this way > http://talklikeaduck.denhaven2.com/articles/2007/07/18/time-flies-while-youre-having-fun-testingHey Rick: I''d like to implement this method of yours as it looks simple and I don''t know how to use R-spec with integration testing. I''ve never done anything with modules though. From what I''ve read, it seems like I should be able to call your now_as method like this: TimeMachine.now_as(2.days.ago) However, even with your module defined in my_test.rb, I get the error "undefined method `now_as'' for MyTest::TimeMachine:Module". How are you calling your ''now_as'' method? Thanks for the advice. Peter -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Nevermind. I didn''t realize I needed to pass the code I want to execute in a time warp inside a block. Here is what I''m using: TimeMachine.now_as(2.days.ago){ my code } Works great! Thanks for sharing your module and pointing me in its direction. No more tedious tricking my db into thinking it''s the past! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Today, I''d probably use some form of stub or mock, probably what''s > built into RSpec.That''s exactly what I do now. I used to have some nifty method to go ''back to the future'', but stubbing works well now. This always tends to come up, so it''s a standard part of my test suites now. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---