Removing framework clutter from autotest failure stacktraces

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.

No Comments Yet

You can be the first to comment!

Speak Your Peace