TechHui

Hawaiʻi's Technology Community

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.

Views: 123

Comment

You need to be a member of TechHui to add comments!

Join TechHui

Comment by Chris Sass on November 6, 2012 at 8:39am

+1

:)

Sponsors

web design, web development, localization

© 2024   Created by Daniel Leuck.   Powered by

Badges  |  Report an Issue  |  Terms of Service