What to do when you can't decipher your unit tests

I've been meaning to follow up on Chris Sass' excellent post on growing pains. A related side effect of code that has grown too complicated is unit tests that are impossible to decipher. As your ActiveRecord model becomes bloated, the tests written for it have to mock out too many things. This makes it nearly impossible to know why the test was created and what, exactly, is supposed to be isolated.

Using the same blog post referenced by Chris (7 Patterns to Refactor Fat ActiveRecord Models), I recently tackled some unwieldy test code. I was able to factor out 15 separate objects (with 15 separate, simpler test modules) and greatly improve the readability and functionality of my code.

It's easy to use Ruby as a procedural language, and easier still, to rely on the framework of Rails. But remember, its a framework created to make you programming life easier. Once it clutters up the objective of your model (or controller), don't forget that it is a fully OO capable language. Put some of your hard-earned OO skills to work.