applicake / README.md secret
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Chuck testar rspec formatter

View README.md

Chuck testr RSpec formatter

This formatter is a game changer... Nope! It's just Chuck TestaR

Requirements

It requires rspec and growl_notify gem. It works best on OS X.

Installation

Since we're using growl notifications you may want to download two additional images (not included in the gist):

curl http://img.skitch.com/20111031-8x26je3q4x41gy17qhh63j539f.png > chuck-normal.png
curl http://img.skitch.com/20111031-gmsuuk85ti7tircttd1237u7u7.png > chuck-nope.png

After that, you're good to go!

Usage

$ rspec -r ./chuck_testar.rb -f ChuckTestar -c chuck_testar_spec.rb
View README.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
require 'rspec/core/formatters/base_text_formatter'
require './notifications'
require './portable'
 
class ChuckTestar < RSpec::Core::Formatters::BaseTextFormatter
def icon(name)
File.join(File.dirname(__FILE__), name)
end
 
def notify(text, icon_filename)
if Object.const_defined? "GrowlNotify"
GrowlNotify.normal({
:title => 'RSpec',
:description => text,
:icon => icon(icon_filename)
})
end
end
 
def say(text)
if Portable.platform == 'linux'
`echo "#{text}" | espeak`
elsif Portable.platform == 'osx'
`say "#{text}"`
end
end
 
def notify_with_voice!(text, icon_filename)
notify(text, icon_filename)
say(text)
end
 
def delay(seconds)
sleep(seconds)
end
 
def start(example_count)
super(example_count)
output.print green('Y')
end
 
def stop
output.print green('p')
output.print green("\n\nYour tests pass!\n")
notify_with_voice!('Your tests pass', 'chuck-normal.png')
delay(2)
if @failed_examples.length > 0
output.print magenta("\n\nNope! It's just Chuck Testa!")
notify_with_voice!("Nope! It\'s just Chuck Testa!", 'chuck-nope.png')
delay(1)
end
end
 
def example_passed(example)
super(example)
output.print green('e')
end
 
def example_pending(example)
super(example)
output.print green('e')
end
 
def example_failed(example)
super(example)
output.print green('e')
end
 
def start_dump
super()
output.puts
end
end
View README.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
require './chuck_testar'
 
describe ChuckTestar do
let(:output) { StringIO.new }
let(:formatter) { ChuckTestar.new(output) }
 
before do
formatter.stub(:delay => true)
end
 
describe "output" do
let(:example) {
double("example 1",
:execution_result => {:status => 'failed', :exception => Exception.new }
)
}
 
it "displays 'Y' at the start of the suite" do
formatter.start(1)
output.string.should =~ /Y/
end
 
it "displays 'e' when examples pass" do
formatter.example_passed(example)
output.string.should =~ /e/
end
 
it "displays 'e' when examples fails" do
formatter.example_failed(example)
output.string.should =~ /e/
end
 
it "displays 'p' at the end of tests suite" do
formatter.stub(:notify_with_voice! => true)
formatter.stop
output.string.should =~ /p/
end
end
 
describe "an failing example" do
it "fails" do
false.should be_true
end
end
 
describe "notifications" do
before do
formatter.stub(:say => true)
end
 
it "display success notification when spec pass" do
formatter.example_passed(example)
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => 'Your tests pass', :icon => formatter.icon('chuck-normal.png'))
formatter.stop
end
 
it "display success and fail notifications when spec fail" do
formatter.example_failed(example)
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => 'Your tests pass', :icon => formatter.icon('chuck-normal.png'))
GrowlNotify.should_receive(:normal).with(:title => 'RSpec', :description => "Nope! It's just Chuck Testa!", :icon => formatter.icon('chuck-nope.png'))
formatter.stop
end
end
end
View README.md
1 2 3 4 5 6 7 8 9 10 11
begin
require "growl_notify"
 
GrowlNotify.config do |config|
config.notifications = ["Chuck Testar"]
config.default_notifications = ["Chuck Testar"]
config.application_name = "Chuck Testar RSpec formatter" # this shoes up in the growl applications list in systems settings
end
rescue LoadError
puts "Please install growl_notify gem to enable growl notifications"
end
View README.md
1 2 3 4 5 6 7 8 9 10 11
module Portable
def self.platform
if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin/i
'windows'
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
'osx'
else
'linux'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.