Saturday, January 24, 2009

OutBlogger and TDD

My RSS reader is working in a fairly simple form. I've tried to engage in test driven development while creating OutBlogger.

Starting from scratch, I've tried following the mantra "write no code unless a test fails." This left me writing tests such as this one:
def test_create_duplicate_feed
   feed_a = Feed.new(:url => "http://feeds.joystiq.com/weblogsinc/joystiq")
   feed_b = Feed.new(:url => "http://feeds.joystiq.com/weblogsinc/joystiq")

   feed_a.save
   assert !feed_b.save
end
This test allowed me to write one line of code in the model:
validates_uniqueness_of :url
Needless to say it was a little slow and frustrating at the start. Since then I've adjusted the mantra and am now just coding the easy, boring stuff and using intermittent TDD for interesting stuff. I do keep away from generating generic scaffolds inside the project, as that creates tons of unnecessary code. This mix of quasi-TDD and avoiding the generate command has tidied up my code a great deal and made iterative development much easier.

No comments:

Post a Comment