Skip to content

Instantly share code, notes, and snippets.

@istro
Forked from brentertz/say_formatter.rb
Created February 27, 2013 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save istro/5045816 to your computer and use it in GitHub Desktop.
Save istro/5045816 to your computer and use it in GitHub Desktop.
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