Fuubar: the instafailing RSpec progress bar formatter

By on (last updated on )

As you might have noticed, I’ve been spending some time trying to get running test suites with RSpec a bit better and faster over the last weeks. This week I looked into RSpec’s formatters.

Aside from the red “F” RSpec will output when a spec fails, there’s no direct feedback that allows you to go fix things immediately. You’ll simply have to wait until your whole suite is done running, or use ^C to interrupt the run. Another thing you can do is use the --fail-fast option I wrote about last week or check out rspec-instafail, which will output the failure details while continuing to run the rest of your specs. Nice.

Besides that, I realized there were more things that could be improved on, like knowing the total number of specs, the number of specs that have run already and maybe even an ETA or something like that. Also, the big string of dots and "F"’s started to seem unnecessary, there should be a nicer way to display this information.

I checked out RSpec’s formatters and realized it was extremely easy to write one, so I got distracted and wrote FffuuuFormatter, which makes RSpec print FFFUUU instead of FFFFF. Heh.

Fuubar

After looking around for a bit, I found an article by @nick_evans posted in 2008, in which he tried to fix some of the issues I’m having with a progress bar formatter. Nick wrote a really nice solution for it using the progressbar gem by @peleteiro.

I decided to continue Nick’s work and got the formatter up to speed with RSpec 2, using rspec-instafail to handle the direct feedback after every failure. I put the whole thing in a gem and @josevalim came up with the name: Fuubar.

Here’s a short video of Fuubar in action:

$ rspec --format Fuubar --color spec

If you want to use Fuubar as your default formatter, simply put the options in your .rspec file:

--format Fuubar
--color

After doing that you can simply run your specs like you’re used to:

$ rspec spec

Fuuture

As always: Let me know how you like it and be sure to create an issue on Github if you have any ideas or run into any issues. Of course you can always fork the project and send a pull request.

Fuubar only works on RSpec 2 right now, but there’s no reason why it would be impossible to make it compatible with earlier versions. Also, Nick’s original code had some functionality to find slow specs, but I omitted it because I couldn’t really find a nice implementation.

So, there’s still a lot to do but I think this is quite an improvement from the current formatters. Maybe we can even turn this into a patch for RSpec to make Fuubar one of the default formatters. What do you think?