-
Rake Stats Isn’t Very Smart
I noticed something at work today. rake stats is dumb when it reports test LOC. This is something to bear in mind when evaluating test coverage mertics, as good test coverage is one thing indicative of the code base.
If you’re anything like me you like to deploy a little metaprogramming to make your tests as DRY as possible. So you might have something like this:
%w[first_name last_name title address postcode email website estate business_type].each do |attribute| it "should not be valid without #{attribute}" do @contact.send "#{attribute}=", nil @contact.should_not be_valid @contact.errors_on(attribute).should include "can't be blank" @contact.send "#{attribute}=", @valid_attributes[attribute] @contact.should be_valid end endThis code generates an expectation for each member of the array object. rake stats will see this as nine LOC, but if you were to do it the long way and explicitly write out all of your expectations, it would count for sixty-three LOC, nine times difference. After a few cases of this, your test coverage stats are going to be distorted and worth less and less.
It’s a bad idea to rely on rake stats to indicate code coverage quality, but this is another reason to give it less weight.
Tue16Feb