pithy, poignant, insightful - or not

Disabling Test::Unit Rake Output

Posted: January 21st, 2009 | Author: Adam | Filed under: Testing | Tags: , , , , | No Comments »

If you’re like me you prefer RSpec to the Test::Unit (the default testing framework that comes with Rails by default). You immediately kill off the “test” folder in your app and bootstrap RSpec with “./script/generate rspec”. When you run the default rake command (’rake’) in the root of your app you are greeted with the following:

OMG - WHAT IS THIS CRAP IN MY CONSOLE?

OMG - WHAT IS THIS CRAP IN MY CONSOLE?

I know these don’t come with RSpec because ‘rake spec’ is silent (because we don’t have any specs yet — which is fine, we’ll build them later, don’t worry). This little thing has annoyed me for a while now but I’ve just had more important things to do instead of digging in and figuring out where this output is being generated, you know, like client work, the stuff that pays the bills.

Today, I took the time to figure it out and it was crazy simple. I’m kicking myself for not checking it out sooner (I feel like such a dirty noob *shakes head*). It turns out that each one of these blank lines represents one level in Test::Unit - unit, functional, and integration. Since I delete the “test” folder on sight (in new projects using RSpec) there aren’t any tests to run and this is actually part of the default output each Test::Unit  run.

Now that we have an understanding of what’s going on here — we have to dig in a little more and figure out where this rake task is being defined. Since Test::Unit is being fired off when we call a ‘rake’ by itself it means that there is a default rake task (’task :default => :sometask’) specified somewhere that is causing this behavior. Another thing I tend to do in my applications is freezing Rails so I don’t have to depend on the version of Rails lives on each machine on which this app is hanging out. This allows me to search through the Rake tasks that come with Rails by default. A good portion of these tasks live in ‘railties’ (general framework utilities) so we can start our search there (in ‘vendor/rails/railties/lib/tasks’ - because ‘lib/tasks’ is where Rake tasks tend to live). In order to search for ‘:default’ within Railties we’ll bust out our trusty friend ‘grep’:

That grep command says: search inside all files ‘-R’ found in ‘vendor/rails/railties/lib/tasks’ for any line containing ‘:default’ and show the line number ‘-n’.

BINGO! There it is! All you need to do is edit ‘vendor/rails/railties/lib/tasks/misc.rake’ and comment out line number one. Then if you run the default rake command ‘rake’ (by itself) you should no longer have to endure the filthy remnants of the Test::Unit.