# Short story on testing

**URL:** <https://www.ruby-forum.com/t/short-story-on-testing/146365>\
**Category:** Rails\
**Created:** [August 20, 2008, 11:27am UTC](https://www.ruby-forum.com/t/short-story-on-testing/146365 "2008-08-20T11:27:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Franz\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ecb155/32.png) [@Franz\_S](https://www.ruby-forum.com/u/Franz_S)\
**Post date:** [August 20, 2008, 11:27am UTC](https://www.ruby-forum.com/t/short-story-on-testing/146365/1 "2008-08-20T11:27:21Z")

</div>

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
