Skip to content

Instantly share code, notes, and snippets.

@dx7
Created January 18, 2012 20:58
Show Gist options
  • Save dx7/1635620 to your computer and use it in GitHub Desktop.
Save dx7/1635620 to your computer and use it in GitHub Desktop.
# Rspec formatter by RAFAELDX7
# Use: rspec --require "dx7_formatter.rb" --format Dx7Formatter -- ./spec/your_spec.rb
require 'rspec/core/formatters/base_text_formatter'
class Dx7Formatter < RSpec::Core::Formatters::BaseTextFormatter
def index
@index ||= -1
@index += 1
end
def example_passed(example)
super(example)
output.print green('.')
end
def example_pending(example)
super(example)
output.print yellow('*')
end
def example_failed(example)
super(example)
output.puts
dump_failure(example, index)
dump_backtrace(example)
exception = example.execution_result[:exception]
growlnotify('red', read_failed_line(exception, example).strip)
end
def start_dump
super()
output.puts
end
def dump_failures
end
def close
output.close if IO === output && output != $stdout
image_color = if @failure_count > 0
"red"
elsif @pending_count > 0
"yellow"
elsif @example_count == 0
"grey"
else
"green"
end
growlnotify(image_color, summary_line(@example_count, @failure_count, @pending_count))
end
def growlnotify(image_color, message)
image_path = "#{`echo $HOME`.strip}/Dropbox/Pictures/autotest_images"
`growlnotify --image "#{image_path}/ruby_#{image_color}.png" -t "RSpec" -m "#{message}"`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment