2007-10-27

Demeter's Revenge

More evidence that if something in Ruby or Rails seems to be more work than it ought to be, you’re probably doing it wrong:

http://www.lukeredpath.co.uk/2007/10/18/demeters-revenge

In this case, mocking ActiveRecord associations was unreasonably inflating the ratio of lines of test code per lines of application code tested.

If ActiveRecord saves you from needing to manually (or otherwise) generate boilerplate ORM code, but you give that advantage back by writing tons of test code, your net advantage just shrank. Also, consider that an excessive ratio of test code to application code acts_as_ball_and_chain, reducing the agility with which you can respond to changing business conditions.

The solution described has two parts: 1) Follow best practices (in this case observe the Law of Demeter) and 2) apply a little more meta-programming goodness.