Hello, I constantly run into this problem when trying to test assertions against time w/ seconds. Since there can be a tiny lapse time between when a test is fired off and the value is tested your test can be off by a second, therefor causing it to fail. For instance. I have an assert select test that will randomly fail because the dynamic time being tested against will have lapsed a second. [code] assert_select "pubDate", 6.days.from_now.gmtime.strftime("%a, %d %b %Y %I:%M:%S GMT") [/code] Now, about 50% of the time, this test will fail and give you a result like such: <"Sun, 11 Nov 2007 21:15:48 GMT"> expected but was <"Sun, 11 Nov 2007 21:15:47 GMT">. Any ideas on how I can make this test less brittle? Thanks, Eric -- 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 -~----------~----~----~----~------~----~------~--~---
Can you find a way to subtract the test field''s time from "now", and allow a delta of (say) 10 seconds? --Michael On Nov 5, 2007 3:17 PM, Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello, > > I constantly run into this problem when trying to test assertions > against time w/ seconds. Since there can be a tiny lapse time between > when a test is fired off and the value is tested your test can be off by > a second, therefor causing it to fail. > > For instance. I have an assert select test that will randomly fail > because the dynamic time being tested against will have lapsed a second. > > [code] > assert_select "pubDate", 6.days.from_now.gmtime.strftime("%a, %d %b %Y > %I:%M:%S GMT") > [/code] > > Now, about 50% of the time, this test will fail and give you a result > like such: > > <"Sun, 11 Nov 2007 21:15:48 GMT"> expected but was > <"Sun, 11 Nov 2007 21:15:47 GMT">. > > Any ideas on how I can make this test less brittle? > > Thanks, > Eric > -- > 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 -~----------~----~----~----~------~----~------~--~---
I''d love to use assert_in_delta but since I''m using assert_select I can''t figure out how to something similar. Michael Graff wrote:> Can you find a way to subtract the test field''s time from "now", and > allow a delta of (say) 10 seconds? > > --Michael-- 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 -~----------~----~----~----~------~----~------~--~---
Clem Rock wrote:> I''d love to use assert_in_delta but since I''m using assert_select I > can''t figure out how to something similar.assert_select yields the found elements (HTML::Node), so you can try something like: assert_select("pubDate") do |el| assert_in_delta el.to_s, ... end --~--~---------~--~----~------------~-------~--~----~ 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 Nov 5, 2007 4:17 PM, Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello, > > I constantly run into this problem when trying to test assertions > against time w/ seconds. Since there can be a tiny lapse time between > when a test is fired off and the value is tested your test can be off by > a second, therefor causing it to fail. > > For instance. I have an assert select test that will randomly fail > because the dynamic time being tested against will have lapsed a second. > > [code] > assert_select "pubDate", 6.days.from_now.gmtime.strftime("%a, %d %b %Y > %I:%M:%S GMT") > [/code] > > Now, about 50% of the time, this test will fail and give you a result > like such: > > <"Sun, 11 Nov 2007 21:15:48 GMT"> expected but was > <"Sun, 11 Nov 2007 21:15:47 GMT">. > > Any ideas on how I can make this test less brittle?I think the most promising approach is to "freeze" time for the duration of the test. Various approaches have been discussed. I think something like this would work well: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195144 Here''s a similar approach of my own design: http://snippets.dzone.com/posts/show/4776 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bob, This was perfect! Thanks so much for this approach. This has been driving me nuts for a while and this approach solves all my time problems. Cheers. Bob Showalter wrote:> On Nov 5, 2007 4:17 PM, Clem Rock <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> >> >> Any ideas on how I can make this test less brittle? > > I think the most promising approach is to "freeze" time for the > duration of the test. Various approaches have been discussed. I think > something like this would work well: > > http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/195144 > > Here''s a similar approach of my own design: > > http://snippets.dzone.com/posts/show/4776-- 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 -~----------~----~----~----~------~----~------~--~---