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.