Skip to content

Instantly share code, notes, and snippets.

@rud
Created February 26, 2010 08:26
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 rud/315530 to your computer and use it in GitHub Desktop.
Save rud/315530 to your computer and use it in GitHub Desktop.
ImmediateFeedbackFormatterGrowl
require 'spec/runner/formatter/base_text_formatter'
# Code is based on standard SpecdocFormatter, but will print full error details as soon as they are found.
# Successful or pending examples are written only as a dot in the output. Header is only printed if errors occur.
#
# To use it, add the following to your spec/spec.opts:
# --require
# spec/support/rspec_immediate_feedback_formatter_growl.rb
# --format
# Spec::Runner::Formatter::ImmediateFeedbackFormatterGrowl
module Spec
module Runner
module Formatter
class ImmediateFeedbackFormatterGrowl < BaseTextFormatter
def add_example_group(example_group)
super
@current_group = example_group.description
end
def example_failed(example, counter, failure)
fail_img = "#{File.basename(__FILE__)}/rails_fail.png"
cmd = "growlnotify --name rspec --identifier rails_fail --image #{fail_img} --message \"#{failure.header}\" --priority Emergency"
# puts cmd
system cmd
if @current_group
output.puts
output.puts @current_group
@current_group = nil # only print the group name once
end
message = if failure.expectation_not_met?
"- #{example.description} (FAILED - #{counter})"
else
"- #{example.description} (ERROR - #{counter})"
end
output.print red("F")
dump_failure(counter, failure) # dump stacktrace immediately
output.flush
end
def example_passed(example)
output.print green(".")
output.flush
end
def example_pending(example, message)
super
output.print yellow("P")
output.flush
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment