Is there a way to simulate the functional test being called on different days? In other words, the functional test may yield a different result when run on different dates. I''d like to set the system date in the test to see how the controller responds on different dates. Thanks! Tom --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tom wrote:> Is there a way to simulate the functional test being called on > different days? In other words, the functional test may yield a > different result when run on different dates. I''d like to set the > system date in the test to see how the controller responds on different > dates. > > Thanks! > TomYou could get the system date from an object, and then use Mocks to control what the object sends out. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tom wrote:> Is there a way to simulate the functional test being called on > different days?You can use a mocking/stubbing library to stub out Time.now in your test setup. Using FlexMock: flexstub(Time).should_recieve(:now).and_return(Time.mktime(2007,1,1,12,49,00)) Another good library is Mocha. Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dan Manges wrote:> You can use a mocking/stubbing library to stub out Time.now in your > test setup.Now that I think about it, this approach really is not good. Most time-sensitive logic should be in your models. In all the methods you write which use Time.now, you should pass it in to the method like this: def my_day_of_the_week_based_method(the_time = Time.now) # do whatever with the_time end Then for your unit tests, you can test it with different times easily. In your functional tests which use this method in the model, you can stub out the model method instead of stubbing out Time.now. Either approach should work, but having the default Time.now parameter in your model methods is a good practice. Dan Manges --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dan Manges wrote:> def my_day_of_the_week_based_method(the_time = Time.now) > # do whatever with the_time > endDon''t forget also adding to your /test/fixtures/model.yml files lines like <% 3.seconds.ago.to_s :db %>. Then your production code can rely on the current time without passing it in. Your test fixture data will always have the correct values relative to the time of the test run. -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---