ChangingThePresent
The Few, The Proud, The Pradipta 416
CV

Grr! rake and Test::Unit errors

bryan / 03.Oct.2008

This was one of those bugs that was just killing me. I absolutely could not figure out why some of my new shiny rake tasks were failing. I went through the motions of uninstalling my custom ruby and rails on my Mac and upgrading instead the system installed Ruby then reinstalling rails and all gems.

It was a lot of work, and actually I produced a neato script to help clean gems. (maybe I’ll post it up here soon)

But it didn’t fix the situation. Several hours of google and forum threads that were only somewhat related, I stumbled on an old Rails bug, wherein “require ‘test/unit’” was being called by something or other. Of course it should only be called when testing and when needed. But it was unfortunately being called on EVERY rake task after anything that was called. The problem was that rake was passing the arguments to Test::Unit::AutoRunner which returned errors and generally hosed the parsing of the rake outcome (which is what I was up to).

Anyhoo, here is my workaround. Quick and dirty, but works. CaveatL only use if you are NOT using Test::Unit for anything good. (i.e. you still haven’t switched to rspec _ ) Or use the second method listed and control the monkey patch a bit.

It can be used in 1 of two ways, I prefer the latter as it gives more control.

  1. Add the module below to the project’s main Rakefile
  2. Add a file to lib called “_rake_helper.rb” and paste the module in there.
For 2., use it in any Rakefile needing to avoid the Test::Unit clash by requiring it

 require 'lib/tasks/_rake_helper'
 include RakeHelper

Here is the module:


 module Test
   module Unit
     class FakeAutoRunner
       class <<self
         def run
           return true
         end
       end
     end
     begin
       silence_warnings do
         const_set("AutoRunner", FakeAutoRunner)
       end
     rescue
     end
   end
 end

Leave a Comment

back to top

micro theme by seaofclouds, and powered with Mephisto Hosting by hostingrails.com