Peter Marklund

Peter Marklund's Home


Rails Patch: Rake :test should not fail silently

Swallowing exceptions and failing silently has to be one of the worst sins you can commit as a programmer and I was surprised to run into that issue with the Rake :test task. The Rake :test task (the default task) will in turn invoke the tasks test:units, test:functionals, and test:integration. Any exceptions raised within these sub tasks are not exposed directly but are merely noted as an overall test failure - obscuring the root cause of the failure. This is obviously not very debugging friendly if you have an exception raised somewhere deep down in the Rake task dependency hierarchy. I submitted a patch to remedy the problem.

3 comment(s)

Comments said 2008-05-02 11:21:

i think the taks test should get thrown out because its very hard some of our teachers cant even pass the test so what make them think we can pass the test they need to just go by credits

Peter Marklund said 2007-03-25 15:01:

This problem was fixed by code even more elegant than mine by Michael Koziarski in the Rails core team: <pre> desc 'Test all units and functionals' task :test do exceptions = ["test:units", "test:functionals", "test:integration"].collect do |task| begin Rake::Task[task].invoke nil rescue =&gt; e e end end.compact exceptions.each {|e| puts e;puts e.backtrace } raise "Test failures" unless exceptions.empty? end </pre> Thanks Michael!

Leo Dirac said 2006-12-02 19:00:

I've also been frustrating by this problem enough to crack open the source and try to fix it. My solution is at I think your code is more elegant though. Thanks for submitting it.