short story on testing

Hello folks,

I thought I’d quickly share an experience I had this morning.

I have a before_save callback in one of my models that sets a boolean attribute depending on the value of another attribute.

I’m heavily into test-driven devt these days, thanks to the peepcode screencast, and saw that my unit test for that model had failures.

I racked my brain for 30 minutes before I realized what was happening. Since Ruby returns the value of the last statement

as the method’s return value, my before_save was returning false when the attribute was set to false, which of course halted Rails’ callback/validation chain, which led to my test failure.

Without proper tests, that error would have easily slipped

through to production. Thanks to TDD, it didn’t.

Regards, Franz