Fearless Fool
2011-Jan-29 15:40 UTC
seeking guidance: writing effective tests for externally sourced data
So first, thanks in no small part to Marnen''s rants, I''ve become a complete RSpec / FactoryGirl / TDD convert. Hey, autotest coupled with Growl is the bee knees! And I''ve even started pushing builds out to Heroku to keep me honest. Now I feel uneasy when I''ve written a piece of code that isn''t covered by an effective test. That''s how it should be. But I''m stumped on how to test the following, so I turn to the collective wisdom of the RoR forum. My app periodically needs to fetch XML data from external sites. To avoid inadvertently pummeling the external servers, I''ve written some extensions to Mechanize that observe the following rules: - any XML data I fetch from the external site is cached - I will NOT fetch if the most recent attempt was less than K hours ago - I will fetch the data if it''s absent or stale (i.e. older then J days) Testing it manually, it works like a champ. But how the heck do I automate the testing? It seems I need to fake up the Mechanize GET method so I can simulate various failure modes, etc. Do I create a FactoryGirl stub (or mock???). So I''m looking for suggestions and (ideally) examples of how experienced testers would test this. TIA. - ff -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2011-Jan-29 16:21 UTC
Re: seeking guidance: writing effective tests for externally sourced data
Fearless Fool wrote in post #978383:> So first, thanks in no small part to Marnen''s rants, I''ve become a > complete RSpec / FactoryGirl / TDD convert. Hey, autotest coupled with > Growl is the bee knees! And I''ve even started pushing builds out to > Heroku to keep me honest. > > Now I feel uneasy when I''ve written a piece of code that isn''t covered > by an effective test. That''s how it should be.Excellent! Glad to have shown someone else the light.> > But I''m stumped on how to test the following, so I turn to the > collective wisdom of the RoR forum. > > My app periodically needs to fetch XML data from external sites. To > avoid inadvertently pummeling the external servers, I''ve written some > extensions to Mechanize that observe the following rules: > > - any XML data I fetch from the external site is cachedThe external site isn''t already setting its HTTP caching headers properly for this?> - I will NOT fetch if the most recent attempt was less than K hours ago > - I will fetch the data if it''s absent or stale (i.e. older then J days) > > Testing it manually, it works like a champ. But how the heck do I > automate the testing? It seems I need to fake up the Mechanize GET > method so I can simulate various failure modes, etc. Do I create a > FactoryGirl stub (or mock???). So I''m looking for suggestions and > (ideally) examples of how experienced testers would test this.Use Webmock, and perhaps VCR. There is an introductory Webmock presentation on my GitHub account.> > TIA. > > - ffBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fearless Fool
2011-Jan-30 04:44 UTC
Re: seeking guidance: writing effective tests for externally sourced data
Marnen Laibow-Koser wrote in post #978394:>> - any XML data I fetch from the external site is cached > The external site isn''t already setting its HTTP caching headers > properly for this?That''s a good suggestion, and I''ll certainly look into heeding the HTTP expiration time stamps. In my case, data isn''t updated on a regular schedule, so the header may be of limited utility. But as I say, I''ll look into it.> Use Webmock, and perhaps VCR. There is an introductory Webmock > presentation on my GitHub account.I looked first at your "Testing Remote Services with WebMock" preso (a tasty appetizer), and then at https://github.com/bblimke/webmock (the main course) -- that''s *exactly* what I need. I''ll be up late tonight wiring it in. Thanks for the pointer! - ff -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Fearless Fool
2011-Jan-30 05:03 UTC
Re: seeking guidance: writing effective tests for externally sourced data
A minor correction: Fearless Fool wrote in post #978457:> Marnen Laibow-Koser wrote in post #978394: >> The external site isn''t already setting its HTTP caching headers >> properly for this? > > That''s a good suggestion, and I''ll certainly look into heeding the HTTP > expiration time stamps...I realize I should have said "Cache-Control HTTP headers" rather than "Expires HTTP header". -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.