Click here to Skip to main content
15,886,422 members
Articles / DevOps / Unit Testing
Tip/Trick

Rspec Pacman Formatter

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
10 Mar 2018CPOL1 min read 5.4K  
Formatting your rails specs with rspec_pacman_formatter

Introduction

Rspec, one of the most popular unit testing frameworks for Ruby these days, gives you the possibility to tweak its default output via Formatters.

Formatters are Ruby classes that you can write to change the behaviour of rspec while it is printing test results in the terminal. Most formatters are packed in Ruby gems and are typically hosted at rubygems.org.

Background

I decided to start my own formatter because I discovered some interesting Unicode characters that I could use to simulate the characters of the classic game Pacman.

The characters I found are listed below:

Unicode character Pacman equivalent
https://www.compart.com/en/unicode/U+15E3 ᗣ Ghosts
https://www.compart.com/en/unicode/U+15E7 ᗧ Pacman
https://www.compart.com/en/unicode/U+2022 • Pacdot

Then if you add a bit of color to these characters, you can achieve something like:

Notice that when one of the specs fail, you will get a random ghost between Blinky, Pinky, Inky or Clyde.

Using the Code

The code is available here and all you need to do is:

  1. Adding the gem dependency in the Gemfile:
    group :test do
      gem 'rspec_pacman_formatter'
    end
  2. Run:
    bundle
  3. Run specs with the --format flag to use the formatter inside rspec_pacman_formatter gem.
    rspec --format RspecPacmanFormatter::Pacman

Points of Interest

This was my first gem that I published on rubygems.org and it has more than 2k downloads already.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer https://golabstech.com
Costa Rica Costa Rica
CTO and Co-founder of Golabs, a software development company located in Costa Rica. I am very passionate about my job and I really enjoy building things with software and make things happening. I am also a professor at Universidad Técnica Nacional because I believe that knowledge should be shared, I really enjoy seeing people grow from students at the university to great professionals and entrepreneurs.

Comments and Discussions

 
-- There are no messages in this forum --