test_notifier 0.1.2 → 0.1.3

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.rdoc CHANGED
@@ -25,7 +25,7 @@ If you're a linux guy, you can choose on of these methods:
25
25
 
26
26
  * Install libnotify-bin and its dependencies: <tt>sudo aptitude install libnotify-bin</tt>
27
27
  * Install xosd-bin: <tt>sudo aptitude install xosd-bin</tt>
28
- * KDE users don't need to install anything: Test Notifier will use +knotify+.
28
+ * KDE users don't need to install anything: Test Notifier will use +knotify+ and in in KDE4 Test Notifier will use +kdialog+.
29
29
 
30
30
  === Windows
31
31
 
@@ -54,7 +54,7 @@ and save the images <tt>none.png</tt>, <tt>passed.png<tt>, <tt>failure.png</tt>
54
54
 
55
55
  == Collaborators
56
56
 
57
- * jeznet - http://github.com/jeznet
57
+ * Szymon (jeznet) Jeż - http://github.com/jeznet
58
58
  * Steve Halasz - http://github.com/woodchuck
59
59
 
60
60
  == License
data/lib/test_notifier.rb CHANGED
@@ -7,15 +7,19 @@ module TestNotifier
7
7
  ERROR_IMAGE = "error.png"
8
8
  FAILURE_TITLE = "FAILED"
9
9
  PASSED_TITLE = "Passed"
10
-
10
+
11
11
  RSPEC_REGEX = /(\d+) examples?, (\d+) failures?(, (\d+) pendings?)?/
12
12
  TEST_UNIT_REGEX = /(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/
13
-
13
+
14
14
  GROWL_REGISTER_FILE = File.expand_path("~/.test_notifier-growl")
15
-
15
+
16
+ HELP_HINT = "For more information see:\n" +
17
+ " * http://github.com/fnando/test_notifier (online)\n" +
18
+ " * #{File.dirname(__FILE__)}/README.markdown (offline)"
19
+
16
20
  def self.notify(image, title, message)
17
21
  image ||= "none.png"
18
-
22
+
19
23
  custom_image = File.join(File.expand_path("~/.test_notifier"), image)
20
24
  image = File.exists?(custom_image) ? custom_image : File.join(File.dirname(__FILE__), "test_notifier", "icons", image)
21
25
 
@@ -25,23 +29,26 @@ module TestNotifier
25
29
  script = File.dirname(__FILE__) + "/test_notifier/register-growl.scpt"
26
30
  system "osascript #{script} > #{GROWL_REGISTER_FILE}"
27
31
  end
28
-
29
- system("growlnotify -n test_notifier --image #{image} -p 2 -m \"#{message}\" -t \"#{title}\"")
32
+ system "growlnotify -n test_notifier --image #{image} -p 2" +
33
+ "-m \"#{message}\" -t \"#{title}\""
30
34
  else
31
35
  puts "No compatible popup notification system installed."
32
- puts "Try installing these:\n* growl"
36
+ puts "Try installing these:\n* Growl"
37
+ puts HELP_HINT
33
38
  end
34
39
  elsif RUBY_PLATFORM =~ /mswin/
35
40
  begin
36
41
  require 'snarl'
37
42
  rescue LoadError
38
- puts 'To be notified by a popup please install Snarl and a ruby gem "snarl".'
43
+ puts 'To be notified by a popup please install Snarl and a ruby gem "ruby-snarl".'
44
+ puts HELP_HINT
39
45
  else
40
46
  Snarl.show_message(title, message, image)
41
47
  end
42
48
  elsif RUBY_PLATFORM =~ /(linux|freebsd)/
43
49
  # if osd_cat is avaible
44
50
  if `which osd_cat` && $? == 0
51
+ require 'test_notifier/osd_cat'
45
52
  color = case image
46
53
  when /#{PASSED_IMAGE}/
47
54
  'green'
@@ -55,9 +62,9 @@ module TestNotifier
55
62
  OsdCat.send "#{title} \n #{message}", color
56
63
  # if dcop server is running
57
64
  elsif `ps -Al | grep dcop` && $? == 0
58
- def self.knotify title, msg
65
+ def self.knotify title, message
59
66
  system "dcop knotify default notify " +
60
- "eventname \'#{title}\' \'#{msg}\' '' '' 16 2"
67
+ "eventname \'#{title}\' \'#{message}\' '' '' 16 2"
61
68
  end
62
69
  knotify title, message
63
70
  # if kdialog is available
@@ -65,10 +72,15 @@ module TestNotifier
65
72
  system("kdialog --title #{title} --passivepopup \"#{message}\" 5")
66
73
  # if notify-send is avaible
67
74
  elsif `which notify-send` && $? == 0
68
- system("notify-send -i #{image} #{title} \"#{message}\"")
75
+ system "notify-send -i #{image} #{title} \"#{message}\""
69
76
  else
70
77
  puts "No popup notification software installed."
71
- 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)"
78
+ puts "Try installing one of this:\n" +
79
+ " * osd_cat (apt-get install xosd-bin),\n" +
80
+ " * knotify (use KDE),\n" +
81
+ " * kdialog (use KDE4),\n" +
82
+ " * notify-send (apt-get install libnotify-bin)"
83
+ puts HELP_HINT
72
84
  end
73
85
  end
74
86
  end
@@ -76,12 +88,12 @@ module TestNotifier
76
88
  def self.rspec?(content)
77
89
  (RSPEC_REGEX =~ content)
78
90
  end
79
-
91
+
80
92
  def self.notification_for_rspec(content)
81
93
  matches, *output = *content.to_s.match(RSPEC_REGEX)
82
94
  output = output.map {|i| i.to_i }
83
95
  e, f, none, p = output
84
-
96
+
85
97
  if f > 0
86
98
  # test has failed
87
99
  title = FAILURE_TITLE
@@ -94,16 +106,16 @@ module TestNotifier
94
106
  # no examples
95
107
  return
96
108
  end
97
-
109
+
98
110
  message = "#{e} examples, #{f} failures, #{p} pending"
99
111
  notify(image, title, message)
100
112
  end
101
-
113
+
102
114
  def self.notification_for_test_unit(content)
103
115
  matches, *output = *content.to_s.match(TEST_UNIT_REGEX)
104
116
  output = output.map {|i| i.to_i }
105
117
  t, a, f, e = output
106
-
118
+
107
119
  if f > 0 || e > 0
108
120
  # test has failed or raised an error
109
121
  title = FAILURE_TITLE
@@ -116,31 +128,9 @@ module TestNotifier
116
128
  # no assertions
117
129
  return
118
130
  end
119
-
131
+
120
132
  message = "#{t} tests, #{a} assertions, #{f} failures, #{e} errors"
121
133
  notify(image, title, message)
122
134
  end
123
135
  end
124
136
 
125
- # Provides a method for popup notifications using osd_cat
126
- # Extracted from http://theadmin.org/articles/2008/2/10/fail-loudly-with-osd_cat-and-autotest
127
- module OsdCat
128
- # TODO move this module to a separate file
129
-
130
- # Use xlsfonts to find the different fonts
131
- FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1"
132
-
133
- # Will display the message on the top of the screen centered, adjust these numbers to suit.
134
- POSITION = "top" # top|middle|bottom
135
- POSITION_OFFSET = "0" # Pixels from position to display (think CSS margin)
136
- ALIGN = "center" # left|right|center
137
-
138
- def self.send msg, color='green'
139
- osd_command = "echo #{msg.inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{color}"
140
-
141
- # osd_cat blocks so start a new thread, otherwise Autotest will wait
142
- Thread.new do
143
- `#{osd_command}`
144
- end
145
- end
146
- end
@@ -0,0 +1,20 @@
1
+ # Provides a method for popup notifications using osd_cat
2
+ # Extracted from http://theadmin.org/articles/2008/2/10/fail-loudly-with-osd_cat-and-autotest
3
+ module OsdCat
4
+ # Use xlsfonts to find the different fonts
5
+ FONT = "-bitstream-charter-bold-r-normal--33-240-100-100-p-206-iso8859-1"
6
+
7
+ # Will display the message on the top of the screen centered, adjust these numbers to suit.
8
+ POSITION = "top" # top|middle|bottom
9
+ POSITION_OFFSET = "0" # Pixels from position to display (think CSS margin)
10
+ ALIGN = "center" # left|right|center
11
+
12
+ def self.send message, color='green'
13
+ osd_command = "echo #{message.inspect} | osd_cat --font=#{FONT} --shadow=0 --pos=#{POSITION} -o #{POSITION_OFFSET} --delay=4 --outline=4 --align=#{ALIGN} -c #{color}"
14
+
15
+ # osd_cat blocks so start a new thread, otherwise Autotest will wait
16
+ Thread.new do
17
+ `#{osd_command}`
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nando Vieira
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-11 00:00:00 -03:00
17
+ date: 2010-05-23 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -37,6 +37,7 @@ files:
37
37
  - lib/test_notifier/icons/error.png
38
38
  - lib/test_notifier/icons/failure.png
39
39
  - lib/test_notifier/icons/passed.png
40
+ - lib/test_notifier/osd_cat.rb
40
41
  - lib/test_notifier/register-growl.scpt
41
42
  - lib/test_notifier/rspec.rb
42
43
  - lib/test_notifier/test_unit.rb