module Speak

Reads test descriptions and results out loud.

Private Class Methods

included(config) click to toggle source

Hooks this into RSpec.

# File lib/speak.rb, line 27
def self.included(config)
  config.before(:each) do |test|
    speak_name(test)
  end

  config.after(:each) do
    speak_result
  end
end

Public Instance Methods

speak_name(test) click to toggle source

Speaks the name of the test.

# File lib/speak.rb, line 4
def speak_name(test)
  say(test_description(test))
end
speak_result() click to toggle source

Speaks the test result.

# File lib/speak.rb, line 9
def speak_result
  if example.pending?
    say("is pending")
  elsif example.exception
    say("failed")
  else
    say("passed")
  end
end

Private Instance Methods

say(message) click to toggle source

Speaks the message.

# File lib/speak.rb, line 22
def say(message)
  system("say", message)
end
test_description(test) click to toggle source

Gets the full description of the test.

# File lib/speak.rb, line 38
def test_description(test)
  meta = test.example.metadata
  path = []
  while meta && meta[:description_args]
    path << meta[:description_args].join
    meta = meta[:example_group]
  end

  description = path.reverse.join(" ")
  description.gsub(/\s+/, " ").gsub(/[^\w ]+/, "")
end