Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New implementation.

  • Loading branch information...
commit bb0c7f2be1bb0774c567857121675df564ff3bf1 0 parents
@fnando authored
3  .gitignore
@@ -0,0 +1,3 @@
+*.gem
+pkg
+nbproject
79 README.rdoc
@@ -0,0 +1,79 @@
+= Test Notifier
+
+Inspired by http://railstips.org/2007/7/23/autotest-growl-pass-fail-notifications
+
+After using Growl notification, I decided to write my own plugin because I have
+to work on Ubuntu and Mac OS X and I missed the notification on my Linux box.
+This plugin works with Linux, Mac OS X and Windows. All you need to do is
+install the specific notification library for your OS.
+
+Instead of displaying lots of notifications for each failure, I prefer to be
+notified about the whole test result (you'll have to check your log
+file anyway in order to clean up the failures/errors).
+
+== Installation
+
+=== Mac OS X
+
+* Install Growl - http://growl.info/
+* Install the growlnotify script located on the "Extras" directory
+* Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab.
+
+=== Linux
+
+If you're a linux guy, you can choose on of these methods:
+
+* Install libnotify-bin and its dependencies: <tt>sudo aptitude install libnotify-bin</tt>
+* Install xosd-bin: <tt>sudo aptitude install xosd-bin</tt>
+* KDE users don't need to install anything: Test Notifier will use +knotify+ and in in KDE4 Test Notifier will use +kdialog+.
+
+=== Windows
+
+* Install Snarl: download from http://www.fullphat.net
+* Install ruby-snarl: <tt>gem install ruby-snarl</tt>
+
+=== All
+
+Then, install the gem with <tt>sudo gem install test_notifier</tt>
+
+== Usage
+
+If you're using Test::Unit you should add <tt>require "test_notifier/runner/test_unit"</tt> to your <tt>test_helper.rb</tt> file.
+
+If you're using RSpec you should add <tt>require "test_notifier/runner/spec"</tt> to your <tt>spec_helper.rb</tt> file. If you're using Rails 2, you need to add <tt>require "test_notifier/runner/rspec"</tt> instead.
+
+If you're using Autotest you should add <tt>require test_notifier/runner/autotest"</tt> to
+the file <tt>~/.autotest</tt>
+
+== Maintainer
+
+* Nando Vieira - http://simplesideias.com.br
+
+== Collaborators
+
+* Szymon (jeznet) Jeż - http://github.com/jeznet
+* Steve Halasz - http://github.com/woodchuck
+* Khaja Minhajuddin - http://minhajuddin.com/
+
+== License
+
+(The MIT License)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Rakefile
@@ -0,0 +1,21 @@
+require "jeweler"
+require "lib/test_notifier/version"
+
+JEWEL = Jeweler::Tasks.new do |gem|
+ gem.name = "test_notifier"
+ gem.email = "fnando.vieira@gmail.com"
+ gem.homepage = "http://github.com/fnando/test_notifier"
+ gem.authors = ["Nando Vieira"]
+ gem.version = TestNotifier::Version::STRING
+ gem.summary = "Display system notifications (dbus, growl and snarl) after running tests."
+ gem.description = <<-TEXT
+Display system notifications (dbus, growl and snarl) after
+running tests. It works on Mac OS X, Linux and Windows. Powerful when used
+with Autotest ZenTest gem for Rails apps.
+TEXT
+
+ gem.files = FileList["{README}.rdoc", "{lib,resources}/**/*"]
+ gem.requirements << "You'll need Growl (Mac OS X), Libnotify, OSD or KDE (Linux) or Snarl (Windows)"
+end
+
+Jeweler::GemcutterTasks.new
39 lib/test_notifier.rb
@@ -0,0 +1,39 @@
+module TestNotifier
+ class << self
+ attr_accessor :__notifier
+ end
+
+ IMAGES = {
+ :fail => File.dirname(__FILE__) + "/../resources/fail.png",
+ :error => File.dirname(__FILE__) + "/../resources/error.png",
+ :success => File.dirname(__FILE__) + "/../resources/success.png"
+ }
+
+ TITLES = {
+ :fail => "Failed!",
+ :success => "Passed!"
+ }
+
+ def self.notify(options)
+ options.merge!({
+ :title => TITLES[options[:status]],
+ :image => IMAGES[options[:status]]
+ })
+
+ notifier.notify(options)
+ end
+
+ def self.notifier
+ self.__notifier ||= begin
+ TestNotifier::Notifier.constants.sort.collect do |const|
+ self.__notifier = TestNotifier::Notifier.const_get(const)
+ break if self.__notifier.supported?
+ end
+
+ self.__notifier
+ end
+ end
+
+ autoload :Notifier, "test_notifier/notifier"
+ autoload :Runner, "test_notifier/runner"
+end
7 lib/test_notifier/autotest.rb
@@ -0,0 +1,7 @@
+require "test_notifier/runner/autotest"
+
+warn <<-TXT
+[TestNotifier] Using `require "test_notifier/autotest"` is deprecated and
+will be removed in the future. Please update your `~/.autotest` file to use
+`require "test_notifier/runner/autotest"` instead.
+TXT
10 lib/test_notifier/notifier.rb
@@ -0,0 +1,10 @@
+module TestNotifier
+ module Notifier
+ autoload :Growl, "test_notifier/notifier/growl"
+ autoload :Snarl, "test_notifier/notifier/snarl"
+ autoload :OsdCat, "test_notifier/notifier/osd_cat"
+ autoload :Knotify, "test_notifier/notifier/knotify"
+ autoload :Kdialog, "test_notifier/notifier/kdialog"
+ autoload :NotifySend, "test_notifier/notifier/notify_send"
+ end
+end
25 lib/test_notifier/notifier/growl.rb
@@ -0,0 +1,25 @@
+module TestNotifier
+ module Notifier
+ module Growl
+ extend self
+
+ SCRIPT = File.dirname(__FILE__) + "/../../../resources/register-growl.scpt"
+ FILE = File.expand_path("~/.test_notifier-growl")
+
+ def supported?
+ RUBY_PLATFORM =~ /darwin/ && `ps -Al | grep GrowlHelper` && `which growlnotify` && $? == 0
+ end
+
+ def notify(options)
+ Thread.new do
+ `growlnotify -n test_notifier --image #{options[:image]} -p 2 -m '#{options[:message]}' -t '#{options[:title]}'`
+ end
+ end
+
+ def register
+ return if File.file?(FILE)
+ system "osascript #{SCRIPT} > #{FILE}"
+ end
+ end
+ end
+end
17 lib/test_notifier/notifier/kdialog.rb
@@ -0,0 +1,17 @@
+module TestNotifier
+ module Notifier
+ module Kdialog
+ extend self
+
+ def supported?
+ RUBY_PLATFORM =~ /(linux|freebsd)/ && `which kdialog` && $? == 0
+ end
+
+ def notify(options)
+ Thread.new do
+ `kdialog --title #{options[:title]} --passivepopup \"#{options[:message]}\" 5`
+ end
+ end
+ end
+ end
+end
17 lib/test_notifier/notifier/knotify.rb
@@ -0,0 +1,17 @@
+module TestNotifier
+ module Notifier
+ module Knotify
+ extend self
+
+ def supported?
+ RUBY_PLATFORM =~ /(linux|freebsd)/ && `ps -Al | grep dcop` && $? == 0
+ end
+
+ def notify(options)
+ Thread.new do
+ `dcop knotify default notify eventname \'#{options[:title]}\' \'#{options[:message]}\' '' '' 16 2`
+ end
+ end
+ end
+ end
+end
17 lib/test_notifier/notifier/notify_send.rb
@@ -0,0 +1,17 @@
+module TestNotifier
+ module Notifier
+ module NotifySend
+ extend self
+
+ def supported?
+ RUBY_PLATFORM =~ /(linux|freebsd)/ && `which notify-send` && $? == 0
+ end
+
+ def notify(options)
+ Thread.new do
+ `notify-send -i #{options[:image]} #{options[:title]} \"#{options[:message]}\"`
+ end
+ end
+ end
+ end
+end
26 lib/test_notifier/notifier/osd_cat.rb
@@ -0,0 +1,26 @@
+module TestNotifier
+ module Notifier
+ module OsdCat
+ extend self
+
+ FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1"
+ POSITION = "top"
+ POSITION_OFFSET = "0"
+ ALIGN = "center"
+ COLORS = {
+ :fail => "orange",
+ :success => "green"
+ }
+
+ def supported?
+ RUBY_PLATFORM =~ /(linux|freebsd)/ && `which osd_cat` && $? == 0
+ end
+
+ def notify(options)
+ Thread.new do
+ `echo #{options[:message].inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{COLORS[options[:status]]}`
+ end
+ end
+ end
+ end
+end
22 lib/test_notifier/notifier/snarl.rb
@@ -0,0 +1,22 @@
+module TestNotifier
+ module Notifier
+ module Snarl
+ extend self
+
+ def supported?
+ return false unless RUBY_PLATFORM =~ /(mswin|mingw)/
+
+ begin
+ require "snarl" unless defined?(Snarl)
+ true
+ rescue LoadError
+ false
+ end
+ end
+
+ def notify(options)
+ Snarl.show_message(options[:title], options[:message], options[:image])
+ end
+ end
+ end
+end
11 lib/test_notifier/rspec.rb
@@ -0,0 +1,11 @@
+if defined?(RSpec)
+ require "test_notifier/runner/rspec"
+else
+ require "test_notifier/runner/spec"
+end
+
+warn <<-TXT
+[TestNotifier] Using `require "test_notifier/rspec"` is deprecated and
+will be removed in the future. Please use `require "test_notifier/runner/spec"`
+or `require "test_notifier/runner/rspec"` for RSpec 2 instead.
+TXT
7 lib/test_notifier/runner.rb
@@ -0,0 +1,7 @@
+module TestNotifier
+ module Runner
+ autoload :RSpec, "test_notifier/runner/rspec"
+ autoload :Spec, "test_notifier/runner/spec"
+ autoload :TestUnit, "test_notifier/runner/test_unit"
+ end
+end
23 lib/test_notifier/runner/autotest.rb
@@ -0,0 +1,23 @@
+require "test_notifier"
+
+Autotest.add_hook :ran_command do |at|
+ begin
+ content = at.results.to_s
+ rspec_matches = content.match(/(\d+) examples?, (\d+) failures?(, (\d+) pendings?)?/)
+ test_unit_matches = content.match(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/)
+
+ if rspec_matches
+ _, examples, failures, pending = *rspec_matches
+ status = failures.to_i > 0 ? :fail : :success
+ message = "#{examples} examples, #{failures} failed, #{pending} pending"
+ TestNotifier.notify(:status => status, :message => message) unless examples.to_i.zero?
+ elsif test_unit_matches
+ _, tests, assertions, failures, errors = *test_unit_matches
+
+ status = failures.to_i > 0 ? :fail : :success
+ message = "#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors"
+ TestNotifier.notify(:status => status, :message => message) unless tests.to_i.zero?
+ end
+ rescue
+ end
+end
18 lib/test_notifier/runner/rspec.rb
@@ -0,0 +1,18 @@
+require "test_notifier"
+require "rspec/core/formatters/base_text_formatter"
+
+class RSpec::Core::Formatters::BaseTextFormatter
+ alias dump_summary_original dump_summary
+
+ def dump_summary(duration, examples, failed, pending)
+ dump_summary_original(duration, examples, failed, pending)
+
+ begin
+ return if examples == 0
+ status = failed > 0 ? :fail : :success
+ message = "#{examples} examples, #{failed} failed, #{pending} pending"
+ TestNotifier.notify(:status => status, :message => message)
+ rescue
+ end
+ end
+end
18 lib/test_notifier/runner/spec.rb
@@ -0,0 +1,18 @@
+require "test_notifier"
+require "spec/runner/formatter/base_text_formatter"
+
+class Spec::Runner::Formatter::BaseTextFormatter
+ alias dump_summary_original dump_summary
+
+ def dump_summary(duration, examples, failed, pending)
+ dump_summary_original(duration, examples, failed, pending)
+
+ begin
+ return if examples == 0
+ status = failed > 0 ? :fail : :success
+ message = "#{examples} examples, #{failed} failed, #{pending} pending"
+ TestNotifier.notify(:status => status, :message => message)
+ rescue
+ end
+ end
+end
22 lib/test_notifier/runner/test_unit.rb
@@ -0,0 +1,22 @@
+require "test_notifier"
+require "test/unit/ui/console/testrunner"
+
+class Test::Unit::UI::Console::TestRunner
+ alias finished_original finished
+
+ def finished(elapsed_time)
+ finished_original(elapsed_time)
+
+ begin
+ re = /(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/
+ _, tests, assertions, failures, errors = *@result.to_s.match(re)
+
+ return if tests.to_i == 0
+
+ status = (failures.to_i + errors.to_i) > 0 ? :fail : :success
+ message = "#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors"
+ TestNotifier.notify(:status => status, :message => message)
+ rescue
+ end
+ end
+end
6 lib/test_notifier/test_unit.rb
@@ -0,0 +1,6 @@
+require "test_notifier/runner/test_unit"
+
+warn <<-TXT
+[TestNotifier] Using `require "test_notifier/test_unit"` is deprecated and
+will be removed in the future. Please use `require "test_notifier/runner/test_unit"` instead.
+TXT
8 lib/test_notifier/version.rb
@@ -0,0 +1,8 @@
+module TestNotifier
+ module Version
+ MAJOR = 0
+ MINOR = 2
+ PATCH = 0
+ STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
+ end
+end
BIN  resources/fail.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN  resources/register-growl.scpt
Binary file not shown
BIN  resources/success.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 test_notifier.gemspec
@@ -0,0 +1,60 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{test_notifier}
+ s.version = "0.2.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Nando Vieira"]
+ s.date = %q{2010-07-26}
+ s.description = %q{Display system notifications (dbus, growl and snarl) after
+running tests. It works on Mac OS X, Linux and Windows. Powerful when used
+with Autotest ZenTest gem for Rails apps.
+}
+ s.email = %q{fnando.vieira@gmail.com}
+ s.extra_rdoc_files = [
+ "README.rdoc"
+ ]
+ s.files = [
+ "README.rdoc",
+ "lib/test_notifier.rb",
+ "lib/test_notifier/autotest.rb",
+ "lib/test_notifier/notifier.rb",
+ "lib/test_notifier/notifier/growl.rb",
+ "lib/test_notifier/notifier/kdialog.rb",
+ "lib/test_notifier/notifier/knotify.rb",
+ "lib/test_notifier/notifier/notify_send.rb",
+ "lib/test_notifier/notifier/osd_cat.rb",
+ "lib/test_notifier/notifier/snarl.rb",
+ "lib/test_notifier/rspec.rb",
+ "lib/test_notifier/runner.rb",
+ "lib/test_notifier/runner/autotest.rb",
+ "lib/test_notifier/runner/rspec.rb",
+ "lib/test_notifier/runner/spec.rb",
+ "lib/test_notifier/runner/test_unit.rb",
+ "lib/test_notifier/test_unit.rb",
+ "lib/test_notifier/version.rb",
+ "resources/fail.png",
+ "resources/register-growl.scpt",
+ "resources/success.png"
+ ]
+ s.homepage = %q{http://github.com/fnando/test_notifier}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Display system notifications (dbus, growl and snarl) after running tests.}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
Please sign in to comment.
Something went wrong with that request. Please try again.