Last active
December 10, 2015 00:19
-
-
Save brentertz/4350421 to your computer and use it in GitHub Desktop.
Custom RSpec formatter that speaks aloud using the say command, if available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec/core/formatters/progress_formatter' | |
# Custom RSpec formatter that speaks aloud using the say command, if available. | |
# Not to be taken too seriously, but fun for annoying your coworkers. | |
# Usage: bundle exec rspec -r ./say_formatter.rb -f SayFormatter spec | |
class SayFormatter < RSpec::Core::Formatters::ProgressFormatter | |
VOICES = %w[Agnes Albert Alex Bad\ News Bahh Bells Boing Bruce Bubbles Cellos | |
Deranged Fred Good\ News Hysterical Junior Kathy Pipe\ Organ | |
Princess Ralph Trinoids Vicki Victoria Whisper Zarvox] | |
EMCEE = { | |
voice: 'Zarvox', | |
rate: 180 | |
} | |
MESSAGES = { | |
positive: %w[Yes! Dude! Sweet! Nice! Pretty\ much\ the\ best! Yo\ Dawg!], | |
negative: %w[No! Dang! Darn! Damn! Herp\ Derp!], | |
indifferent: %w[Meh! Whateva!] | |
} | |
def start(example_count) | |
super example_count | |
say 'Here we go!', EMCEE[:voice], EMCEE[:rate] | |
end | |
def dump_summary(duration, example_count, failure_count, pending_count) | |
super duration, example_count, failure_count, pending_count | |
say "#{example_count} examples were run in #{duration} seconds. #{failure_count} failed and #{pending_count} were pending.", EMCEE[:voice], EMCEE[:rate] | |
end | |
def example_passed(example) | |
super example | |
say MESSAGES[:positive].sample | |
end | |
def example_failed(example) | |
super example | |
say MESSAGES[:negative].sample | |
end | |
def example_pending(example) | |
super example | |
say MESSAGES[:indifferent].sample | |
end | |
private | |
def say(message, voice=VOICES.sample, rate=Random.new.rand(150..500)) | |
system("say #{message} -v #{voice} -r #{rate}") if can_speak? | |
end | |
def can_speak? | |
@can_speak ||= system('which say > /dev/null') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now available as a gem --> https://github.com/brentertz/holla