Rake is my new F5

The last couple of days I’ve been doing a bunch of refactoring, as I tend to do whenever I’ve reached a kind of plateau on what I’m working on. It’s always good, once things work, to go back and improve the design.
I try to write tests before I write code, so that I’m guaranteed to have tests for every feature. I can run those tests at will to make sure my code works. If I couldn’t do that, I’d be much more reluctant to change anything once the code works, for fear I’ll break something important but not really know it until it’s too late.
But it’s funny how old habits – like pressing F5 in Visual Studio 2005 every time I made a change, just to make sure the app still compiled and worked ok – die hard. Really hard. After I made all these changes in my Rails app, my first instinct was to “run” it and make sure nothing broke. Because Ruby does not have a compilation phase, one typo in a local variable name can go undetected until runtime.
Then I remembered my tests and realized I can just run all my tests to make sure that the app still does what I want it to do:
/dev/app$ rake
All my tests still passed, and it felt great.
Now, I’m not egomaniacal enough to believe that I have perfect test coverage, so I still fired up script/server and manually put the app through its paces. But knowing that the full regressions suite passed made a big difference when it came time to pull the trigger and check in all of my changes.
I’m probably in the minority, here. I know that writing tests is not something everyone does, and writing tests first is less common still.
I’m curious to know what you all do. Does running your app in a browser feel sufficient for you? Do you write tests? Do you wish you wrote tests? If so, what stops you?



