Removing framework clutter from autotest failure stacktraces

29 06 2007

If you’re programming in Ruby, then in the list of “should be’s” is “using autotest“, assuming you’re doing automated testing, which of course is a giant “should be”. One problem if you’re using a bunch of gems or Rails is that their code works and yours is broken but the failure stacktraces you’re reading contain their method names mixed in with yours. 99% of the time this is distracting. So, using some code from Faisal that did the same thing with an older version of Autotest but doesn’t work in the latest release, I hacked up the code to help remove unwanted text from Autotest test output. And now I present it to you.

This goes in your .autotest file:

Autotest.add_hook :ran_command do |autotest|
  eliminate_matching = [%r{vendor/plugins/mocha}]
  modify_matching = {%r{/Applications/Locomotive2/.*/gems} => '{gems}'}

  eliminate_matching.each do |u|
    autotest.results = autotest.results.delete_if do |line|
      line.match(u)
    end
  end

  modify_matching.each do |k,v|
    autotest.results.collect! do |line|
      line.gsub(k, v)
    end
  end

  puts autotest.results
end

Note that autotest will still print the unfiltered version; the filtered output will print afterwards, so just ignore the unfiltered stuff.


Actions

Informations

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>