Prettier MiniTest for Ruby 1.9
The default test library in Ruby 1.9 is now MiniTest, and Test::Unit is now a wrapper around MiniTest. Here’s the snippet from the Ruby 1.9 release notes:
* minitest
o Our new testing library which is faster, cleaner and easier
to read than the old test/unit.
o You can introduce the old test/unit as testunit gem through
RubyGems if you want.
The problem with both the old and new ruby test libraries is that long running tests withheld error/failure information until the whole suite finished. Turn helped solved this, but it doesn’t have a runner for minitest – the turn codebase has a TODO note to implement a minitest runner though.
I decided to look at minitest and implement a hackish turn-like printer. It’s ugly, but I like the results. This gist is what I came up with. If someone knows how turn’s internal works, I would love to patch something into turn for minitest. I’ve only glanced at turn’s codebase, so I don’t know too much about it.
Anyways, copy the gist your test_helper.rb and you’re all set! It requires you have the ansi gem installed. This is what it looks like in my terminal:

Grab the code here: http://gist.github.com/356945
3 comments
trans Apr 09, 2010
Very nice work. I can help incorporate this into Turn.
The way turn works is to have a Runner instance and a Reporter instance. The Runner is a subclass of TestUnit's own UI::Console::TestRunner, which gets used in it's stay. The Runner invokes the given Reporter as certain events in test execution occur. Eg.Reporter#start_test, Reporter#pass, etc.
Since MiniTest doesn't have a separate runner class, we'll have to use MiniTest::Unit itself as you did in your gist. It would be nice if we could subclass MiniTest::Unit but I'm not sure that would work, but we can try it. Then we need to separate your output logic into a Reporter class and tie the two together.
I fear it may be tricky work, which is why I have not attempted it yet. But it you are willing to work on it too, I will lay the ground structure.
John Barnette Apr 09, 2010
minitest works fine with subclassing, should you decide to integrate like that.
paydro Apr 15, 2010
Thanks for the tip! I'll try and put something together on github and send a pull request.
Add a Comment