Peter Marklund

Peter Marklund's Home

Thu November 09, 2006

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.


Leo Dirac said over 8 years ago:

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.


Peter Marklund said over 8 years ago:

This problem was fixed by code even more elegant than mine by Michael Koziarski in the Rails core team:

desc 'Test all units and functionals'
task :test do
  exceptions = ["test:units", "test:functionals", "test:integration"].collect do |task|
    rescue => e
  exceptions.each {|e| puts e;puts e.backtrace }
  raise "Test failures" unless exceptions.empty?

Thanks Michael!

-------------------------------------------------------------------------------- said over 7 years ago:

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