How to get notified when your test suite is done running

This trick will interrupt you when your tests are finished, letting you know it's time to get back to coding.

Running automated tests is a common activity in modern web development. Often, you'll head off to see what's going on in the worlds of: your email, Slack, hacker news, etc.

With this handy script you can get interrupted when your tests are finished letting you know it's time to get back to coding.

At Viget, we're partial to using RSpec with our Ruby on Rails projects. In order to add the notification, all we need to do is run our regular rspec command with a few more commands chained on the end.

I'm a fan of making bash aliases in my ~/.bash_profile for commands I use often, so here it is in bash alias (+function) form:

# ~/.bash_profile
berfunction() {
  bundle exec rspec $* ; tput bel ; osascript -e 'display notification "Tests are done." with title "Back To Coding!"'

alias ber=berfunction

Now, all you need to do is run:

ber or ber spec/your_spec_file_spec.rb which adds the notification functionality. Now, you'll be back to working with less distracted time!

Know any other bash or workflow automation tips? Share them in the comments below!

Mike is a developer who uses his computer and electrical engineering degrees to craft complex but streamlined back-end systems for clients such as Shure and Privia Medical Group.

More articles by Mike