fnando-test_notifier 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -1,13 +1,10 @@
1
- test_notifier
1
+ test\_notifier
2
2
  =============
3
3
 
4
- * [http://github.com/fnando/test_notifier](http://github.com/fnando/test_notifier)
5
-
6
4
  DESCRIPTION:
7
5
  ------------
8
6
 
9
- Inspired by
10
- http://railstips.org/2007/7/23/autotest-growl-pass-fail-notifications
7
+ Inspired by <http://railstips.org/2007/7/23/autotest-growl-pass-fail-notifications>
11
8
 
12
9
  After using Growl notification, I decided to write my own plugin because I have
13
10
  to work on Ubuntu and Mac OS X and I missed the notification on my Linux box.
@@ -21,28 +18,36 @@ file anyway in order to clean up the failures/errors).
21
18
  INSTALLATION:
22
19
  -------------
23
20
 
24
- ###Mac OS X
21
+ ### Mac OS X
25
22
 
26
- 1) Install Growl (http://growl.info/)
27
- 2) Install the growlnotify script located on the "Extras" directory
28
- 3) Open the Growl Preference Page (System > Growl) and activate the
23
+ 1. Install Growl (<http://growl.info/>)
24
+ 2. Install the growlnotify script located on the "Extras" directory
25
+ 3. Open the Growl Preference Page (System > Growl) and activate the
29
26
  options "Listen for incoming notifications" and "Allow remote
30
27
  application registration" on the Network tab.
31
28
 
32
- ###Linux
29
+ ### Linux
30
+
31
+ If you're a linux guy, you can choose on of these methods:
33
32
 
34
- 1) Install libnotify-bin ant its dependencies:
33
+ 1. Install libnotify-bin and its dependencies:
35
34
 
36
- aptitude install libnotify-bin
35
+ sudo aptitude install libnotify-bin
36
+
37
+ 2. Install xosd-bin
37
38
 
38
- ###Windows
39
+ sudo aptitude install xosd-bin
40
+
41
+ 3. KDE users don't need to install anything: test\_notifier will use `knotify`.
39
42
 
40
- 1) Install Snarl: download from http://www.fullphat.net/
41
- 2) Install ruby-snarl:
43
+ ### Windows
44
+
45
+ 1. Install Snarl: download from <http://www.fullphat.net/>
46
+ 2. Install ruby-snarl:
42
47
 
43
48
  gem install ruby-snarl
44
49
 
45
- ###All
50
+ ### All
46
51
 
47
52
  Then, install the gem:
48
53
 
@@ -58,7 +63,9 @@ USAGE:
58
63
  ------
59
64
 
60
65
  If you're using Test::Unit you should add `require "test_notifier/test_unit"`
66
+
61
67
  If you're using RSpec you should add `require "test_notifier/rspec"`
68
+
62
69
  If you're using Autotest you should add `require "test_notifier/autotest"` to
63
70
  the file `~/.autotest`
64
71
 
@@ -68,7 +75,12 @@ and save the images `none.png`, `passed.png`, `failure.png` and `error.png`.
68
75
  MAINTAINER
69
76
  ----------
70
77
 
71
- * Nando Vieira ([http://simplesideias.com.br](http://simplesideias.com.br))
78
+ * Nando Vieira (<http://simplesideias.com.br>)
79
+
80
+ COLLABORATORS
81
+ -------------
82
+
83
+ * jeznet (<http://github.com/jeznet>)
72
84
 
73
85
  LICENSE:
74
86
  --------
data/Rakefile CHANGED
@@ -1,11 +1,12 @@
1
- require 'rake'
1
+ require "rubygems"
2
+ require "rake"
2
3
 
3
4
  PKG_FILES = %w(Rakefile test_notifier.gemspec History.txt License.txt README.markdown TODO.txt) +
4
5
  Dir["lib/**/*"]
5
6
 
6
7
  spec = Gem::Specification.new do |s|
7
8
  s.name = "test_notifier"
8
- s.version = "0.0.10"
9
+ s.version = "0.1.0"
9
10
  s.summary = "Display system notifications (dbus, growl and snarl) after running tests."
10
11
  s.authors = ["Nando Vieira"]
11
12
  s.email = ["fnando.vieira@gmail.com"]
@@ -33,7 +34,7 @@ namespace :gem do
33
34
  spec.instance_variables.each do |ivar|
34
35
  value = spec.instance_variable_get(ivar)
35
36
  name = ivar.split("@").last
36
- value = Time.now if name == "date"
37
+ next if name == "date"
37
38
 
38
39
  next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
39
40
  if name == "dependencies"
data/lib/test_notifier.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'snarl' if RUBY_PLATFORM =~ /mswin/
2
-
3
1
  module TestNotifier
4
2
  # create a .test_notifier at your home
5
3
  # directory and save the images as passed.png,
@@ -13,6 +11,8 @@ module TestNotifier
13
11
  RSPEC_REGEX = /(\d+) examples?, (\d+) failures?(, (\d+) pendings?)?/
14
12
  TEST_UNIT_REGEX = /(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/
15
13
 
14
+ GROWL_REGISTER_FILE = File.expand_path("~/.test_notifier-growl")
15
+
16
16
  def self.notify(image, title, message)
17
17
  image ||= "none.png"
18
18
 
@@ -20,14 +20,56 @@ module TestNotifier
20
20
  image = File.exists?(custom_image) ? custom_image : File.join(File.dirname(__FILE__), "test_notifier", "icons", image)
21
21
 
22
22
  if RUBY_PLATFORM =~ /darwin/
23
- system("growlnotify -n test_notifier --image #{image} -p 2 -m \"#{message}\" -t \"#{title}\"")
23
+ if `ps -Al | grep GrowlHelper` && `which growlnotify` && $? == 0
24
+ unless File.file?(GROWL_REGISTER_FILE)
25
+ script = File.dirname(__FILE__) + "/test_notifier/register-growl.scpt"
26
+ system "osascript #{script} > #{GROWL_REGISTER_FILE}"
27
+ end
28
+
29
+ system("growlnotify -n test_notifier --image #{image} -p 2 -m \"#{message}\" -t \"#{title}\"")
30
+ else
31
+ puts "No compatible popup notification system installed."
32
+ puts "Try installing these:\n* growl"
33
+ end
24
34
  elsif RUBY_PLATFORM =~ /mswin/
25
- Snarl.show_message(title, message, image)
35
+ begin
36
+ require 'snarl'
37
+ rescue LoadError
38
+ puts 'To be notified by a popup please install Snarl and a ruby gem "snarl".'
39
+ else
40
+ Snarl.show_message(title, message, image)
41
+ end
26
42
  elsif RUBY_PLATFORM =~ /(linux|freebsd)/
27
- system("notify-send -i #{image} #{title} \"#{message}\"")
43
+ # if osd_cat is avaible
44
+ if `which osd_cat` && $? == 0
45
+ color = case image
46
+ when /#{PASSED_IMAGE}/
47
+ 'green'
48
+ when /#{FAILURE_IMAGE}/
49
+ 'orange'
50
+ when /#{ERROR_IMAGE}/
51
+ 'red'
52
+ else
53
+ 'white'
54
+ end
55
+ OsdCat.send "#{title} \n #{message}", color
56
+ # if dcop server is running
57
+ elsif `ps -Al | grep dcop` && $? == 0
58
+ def self.knotify title, msg
59
+ system "dcop knotify default notify " +
60
+ "eventname \'#{title}\' \'#{msg}\' '' '' 16 2"
61
+ end
62
+ knotify title, message
63
+ # if notify-send is avaible
64
+ elsif `which notify-send` && $? == 0
65
+ system("notify-send -i #{image} #{title} \"#{message}\"")
66
+ else
67
+ puts "No popup notification software installed."
68
+ puts "Try installing one of this:\n * osd_cat (apt-get install xosd-bin),\n * knotify (use KDE),\n * notify-send (apt-get install libnotify-bin)"
69
+ end
28
70
  end
29
71
  end
30
-
72
+
31
73
  def self.rspec?(content)
32
74
  (RSPEC_REGEX =~ content)
33
75
  end
@@ -76,3 +118,26 @@ module TestNotifier
76
118
  notify(image, title, message)
77
119
  end
78
120
  end
121
+
122
+ # Provides a method for popup notifications using osd_cat
123
+ # Extracted from http://theadmin.org/articles/2008/2/10/fail-loudly-with-osd_cat-and-autotest
124
+ module OsdCat
125
+ # TODO move this module to a separate file
126
+
127
+ # Use xlsfonts to find the different fonts
128
+ FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1"
129
+
130
+ # Will display the message on the top of the screen centered, adjust these numbers to suit.
131
+ POSITION = "top" # top|middle|bottom
132
+ POSITION_OFFSET = "0" # Pixels from position to display (think CSS margin)
133
+ ALIGN = "center" # left|right|center
134
+
135
+ def self.send msg, color='green'
136
+ osd_command = "echo #{msg.inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{color}"
137
+
138
+ # osd_cat blocks so start a new thread, otherwise Autotest will wait
139
+ Thread.new do
140
+ `#{osd_command}`
141
+ end
142
+ end
143
+ end
@@ -2,7 +2,6 @@
2
2
  # RUN : 'rake gem:update_gemspec'
3
3
 
4
4
  Gem::Specification.new do |s|
5
- s.date = "Sat Sep 27 15:24:55 -0300 2008"
6
5
  s.authors = ["Nando Vieira"]
7
6
  s.require_paths = ["lib"]
8
7
  s.required_rubygems_version = ">= 0"
@@ -19,11 +18,12 @@ Gem::Specification.new do |s|
19
18
  "lib/test_notifier/icons/error.png",
20
19
  "lib/test_notifier/icons/failure.png",
21
20
  "lib/test_notifier/icons/passed.png",
21
+ "lib/test_notifier/register-growl.scpt",
22
22
  "lib/test_notifier/rspec.rb",
23
23
  "lib/test_notifier/test_unit.rb",
24
24
  "lib/test_notifier.rb"]
25
25
  s.email = ["fnando.vieira@gmail.com"]
26
- s.version = "0.0.10"
26
+ s.version = "0.1.0"
27
27
  s.homepage = "http://github.com/fnando/test_notifier"
28
28
  s.requirements = ["You'll need Growl (Mac OS X), Libnotify (Linux) or Snarl (Windows)"]
29
29
  s.name = "test_notifier"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fnando-test_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-27 11:24:55 -07:00
12
+ date: 2009-03-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubigen
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -43,6 +44,7 @@ files:
43
44
  - lib/test_notifier/icons/error.png
44
45
  - lib/test_notifier/icons/failure.png
45
46
  - lib/test_notifier/icons/passed.png
47
+ - lib/test_notifier/register-growl.scpt
46
48
  - lib/test_notifier/rspec.rb
47
49
  - lib/test_notifier/test_unit.rb
48
50
  - lib/test_notifier.rb