Last Updated: February 25, 2016
·
2.943K
· mcansky

Rspec colors and spec_helper

I really like to split my base lib modules in separate gems. It does make things a bit more complex sometimes but it also remove code and tests away from your main subject of attention and keep things simple.

Bundler helps to setup a basic gem skeleton (http://bundler.io/v1.6/rubygems.html) but then you are pretty much on your own.

It's quite easy to add your favourite test lib in : add it in the gem spec then, prepare the spec_helper. In the case of Rspec the default config is pretty ... boring. It's all white dots !

It took me a bit of searches to find how to specify the formatter in the spec_helper :

RSpec.configure do |config|
  config.color = true
end

That line will bring back the green/red of old and you might be happy with just this.
I really like colours in my specs, but I also like a lot of them. There are 2 gems to use for extra colour :

NyanCatFormatter does what you can expect from its name : display a colourful Nyan Cat crossing the terminal. You even play the music. String to use with the formatter : 'NyanCatFormatter'.

The Rainbow formatter is a tad simpler, but also quite colourful. String to use with the formatter : 'Rainbow'.

RSpec.configure do |config|
  config.color = true
  config.formatter = 'NyanCatFormatter'
end

Those will not change the quality of your tests. So go and do some more Fabulous coding !