Skip to content
Browse files

add simple notification by using detection from autotest-notification

  • Loading branch information...
1 parent f34a59f commit 13bbe224935870c54cf8a7ab3c6406d5557f09be @grosser committed
Showing with 55 additions and 1 deletion.
  1. +1 −0 Rakefile
  2. +3 −1 Readme.md
  3. +1 −0 autotest-standalone.gemspec
  4. +4 −0 lib/autotest.rb
  5. +46 −0 lib/autotest/notify.rb
View
1 Rakefile
@@ -58,6 +58,7 @@ begin
gem.summary = "Autotest, without ZenTest"
gem.homepage = "http://github.com/grosser/autotest"
gem.authors = ["Ryan Davis", "Michael Grosser"]
+ gem.files << 'lib/autotest/notify.rb'
end
Jeweler::GemcutterTasks.new
View
4 Readme.md
@@ -1,4 +1,4 @@
-Standalone autotest extracted from ZenTest.
+Standalone autotest extracted from ZenTest.
As soon as you save a file, autotest will run the matching tests.
@@ -9,6 +9,7 @@ Improvements over ZenTest
- `-p` use parallel_tests to run tests (Test::Unit only)
- `-s` use any style you want -> `alias autospec2="autotest --style rspec2"`
- `-b` use bundle exec to run tests
+ - `-n` notify about results (simple + experimental)
- simplified test setup
- simplified packaging
- less globals
@@ -39,6 +40,7 @@ Usage
-r, --rc CONFIG Path to config file. (Defaults to ~/.autotest or current_dir/.autotest)
-s, --style STYLE Which style to use, e.g. rspec, rspec2
-b, --bundle-exec Use bundle exec to run tests
+ -n, --notify Notify about success and failure via popups
-h, --help Show this.
Windows needs [diff.exe](http://gnuwin32.sourceforge.net/packages.html)
View
1 autotest-standalone.gemspec
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
"lib/autotest.rb",
"lib/autotest/autoupdate.rb",
"lib/autotest/bundler.rb",
+ "lib/autotest/notify.rb",
"lib/autotest/once.rb",
"lib/autotest/rcov.rb",
"lib/autotest/restart.rb",
View
4 lib/autotest.rb
@@ -136,6 +136,10 @@ def self.parse_options
require 'autotest/bundler'
end
+ opts.on("-n", "--notify", "Notify about success and failure via popups") do
+ require 'autotest/notify'
+ end
+
opts.on "-h", "--help", "Show this." do
puts opts
exit 1
View
46 lib/autotest/notify.rb
@@ -0,0 +1,46 @@
+class Autotest
+ class Notify
+ def self.notify(state)
+ title = "#{state.to_s.capitalize} -- Autotest"
+
+ command = case RUBY_PLATFORM
+ when /linux/
+ title = "'#{title}'"
+ case linux_lib
+ when :'notify-send' then "#{linux_lib} #{title}"
+ when :kdialog then "#{linux_lib} --title #{title}"
+ when :zenity then "#{linux_lib} --title #{title}"
+ end
+ when /darwin/
+ "growlnotify -n autotest -t #{title}"
+ when /cygwin/
+ "sncmd /m '#{title}'"
+ when /mswin/
+ require 'snarl'
+ Snarl.show_message(title)
+ end
+
+ system command
+ end
+
+ private
+
+ def self.linux_lib
+ libs = [:'notify-send', :kdialog, :zenity]
+ @@linux_lib ||= libs.detect do |l|
+ system("which #{l} > /dev/null 2>&1")
+ end or puts("Install one of #{libs.join(', ')} to get notified")
+ end
+ end
+end
+
+[:red, :green, :all_good].each do |hook|
+ Autotest.add_hook hook do
+ begin
+ Autotest::Notify.notify(hook)
+ rescue Exception => e # errors in autotest would fail silently
+ puts e.to_s
+ puts e.backtrace
+ end
+ end
+end

0 comments on commit 13bbe22

Please sign in to comment.
Something went wrong with that request. Please try again.