test_notifier 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +7 -1
- data/lib/test_notifier.rb +14 -9
- data/lib/test_notifier/notifier.rb +28 -0
- data/lib/test_notifier/version.rb +2 -2
- data/test/notifier_test.rb +39 -0
- data/test/test_helper.rb +15 -0
- data/test/test_notifier_test.rb +40 -0
- metadata +12 -7
data/README.rdoc
CHANGED
@@ -40,11 +40,17 @@ Then, install the gem with <tt>sudo gem install test_notifier</tt>
|
|
40
40
|
|
41
41
|
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.
|
42
42
|
|
43
|
-
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
|
43
|
+
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 RSpec 2, you need to add <tt>require "test_notifier/runner/rspec"</tt> instead.
|
44
44
|
|
45
45
|
If you're using Autotest you should add <tt>require test_notifier/runner/autotest"</tt> to
|
46
46
|
the file <tt>~/.autotest</tt>
|
47
47
|
|
48
|
+
You can define your notifier.
|
49
|
+
|
50
|
+
TestNotifier.default_notifier = :growl
|
51
|
+
|
52
|
+
The available notifiers are <tt>:growl</tt>, <tt>:kdialog</tt>, <tt>:knotify</tt>, <tt>:notify_send</tt>, <tt>:osd_cat</tt> and <tt>:snarl</tt>.
|
53
|
+
|
48
54
|
== Maintainer
|
49
55
|
|
50
56
|
* Nando Vieira - http://simplesideias.com.br
|
data/lib/test_notifier.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
module TestNotifier
|
2
2
|
class << self
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :__notifier__
|
4
|
+
attr_accessor :default_notifier
|
4
5
|
end
|
5
6
|
|
7
|
+
extend self
|
8
|
+
|
9
|
+
class UnsupportedNotifierError < StandardError; end
|
10
|
+
|
6
11
|
IMAGES = {
|
7
12
|
:fail => File.dirname(__FILE__) + "/../resources/fail.png",
|
8
13
|
:error => File.dirname(__FILE__) + "/../resources/error.png",
|
@@ -14,7 +19,7 @@ module TestNotifier
|
|
14
19
|
:success => "Passed!"
|
15
20
|
}
|
16
21
|
|
17
|
-
def
|
22
|
+
def notify(options)
|
18
23
|
options.merge!({
|
19
24
|
:title => TITLES[options[:status]],
|
20
25
|
:image => IMAGES[options[:status]]
|
@@ -23,14 +28,14 @@ module TestNotifier
|
|
23
28
|
notifier.notify(options)
|
24
29
|
end
|
25
30
|
|
26
|
-
def
|
27
|
-
self.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
31
|
+
def notifier
|
32
|
+
self.__notifier__ ||= begin
|
33
|
+
notifier = nil
|
34
|
+
notifier = TestNotifier::Notifier.supported_notifier_from_name(default_notifier) if default_notifier
|
35
|
+
notifier = TestNotifier::Notifier.supported_notifiers.first unless notifier
|
32
36
|
|
33
|
-
|
37
|
+
raise UnsupportedNotifierError, "You have no supported notifiers installed. Please read documentation." unless notifier
|
38
|
+
notifier
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
@@ -6,5 +6,33 @@ module TestNotifier
|
|
6
6
|
autoload :Knotify, "test_notifier/notifier/knotify"
|
7
7
|
autoload :Kdialog, "test_notifier/notifier/kdialog"
|
8
8
|
autoload :NotifySend, "test_notifier/notifier/notify_send"
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def notifiers
|
13
|
+
constants.collect do |name|
|
14
|
+
const_get(name)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def supported_notifiers
|
19
|
+
notifiers.select {|notifier| notifier.supported?}
|
20
|
+
end
|
21
|
+
|
22
|
+
def from_name(name)
|
23
|
+
notifier = const_get(classify(name.to_s))
|
24
|
+
rescue NameError
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def supported_notifier_from_name(name)
|
29
|
+
notifier = from_name(name)
|
30
|
+
notifier && notifier.supported? ? notifier : nil
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def classify(string)
|
35
|
+
string.gsub(/_(.)/sm) { "#{$1.upcase}" }.gsub(/^(.)/) { "#{$1.upcase}" }
|
36
|
+
end
|
9
37
|
end
|
10
38
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestNotifier::NotifierTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
unsupport_all_notifiers
|
6
|
+
end
|
7
|
+
|
8
|
+
test "retrieve list of supported notifiers" do
|
9
|
+
TestNotifier::Notifier::Snarl.expects(:supported?).returns(true)
|
10
|
+
TestNotifier::Notifier::Knotify.expects(:supported?).returns(true)
|
11
|
+
|
12
|
+
assert_equal 2, TestNotifier::Notifier.supported_notifiers.size
|
13
|
+
end
|
14
|
+
|
15
|
+
test "retrieve list of all notifiers" do
|
16
|
+
assert_equal 6, TestNotifier::Notifier.notifiers.size
|
17
|
+
end
|
18
|
+
|
19
|
+
test "return notifier by its name" do
|
20
|
+
assert_equal TestNotifier::Notifier::OsdCat, TestNotifier::Notifier.from_name(:osd_cat)
|
21
|
+
assert_equal TestNotifier::Notifier::NotifySend, TestNotifier::Notifier.from_name(:notify_send)
|
22
|
+
assert_equal TestNotifier::Notifier::Growl, TestNotifier::Notifier.from_name(:growl)
|
23
|
+
end
|
24
|
+
|
25
|
+
test "return notifier by its name when supported" do
|
26
|
+
TestNotifier::Notifier::Snarl.expects(:supported?).returns(true)
|
27
|
+
|
28
|
+
assert_equal TestNotifier::Notifier::Snarl, TestNotifier::Notifier.supported_notifier_from_name(:snarl)
|
29
|
+
end
|
30
|
+
|
31
|
+
test "return nil when have supported notifiers" do
|
32
|
+
assert_nil TestNotifier::Notifier.supported_notifier_from_name(:snarl)
|
33
|
+
end
|
34
|
+
|
35
|
+
test "return nil when an invalid notifier name is provided" do
|
36
|
+
assert_nil TestNotifier::Notifier.from_name(:invalid)
|
37
|
+
assert_nil TestNotifier::Notifier.supported_notifier_from_name(:invalid)
|
38
|
+
end
|
39
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
gem "test-unit"
|
2
|
+
require "test/unit"
|
3
|
+
require "mocha"
|
4
|
+
|
5
|
+
require "test_notifier"
|
6
|
+
|
7
|
+
class Test::Unit::TestCase
|
8
|
+
private
|
9
|
+
def unsupport_all_notifiers
|
10
|
+
TestNotifier::Notifier.constants.each do |name|
|
11
|
+
notifier = TestNotifier::Notifier.const_get(name)
|
12
|
+
notifier.stubs(:supported?).returns(false)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class TestNotifierTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
TestNotifier.__notifier__ = nil
|
6
|
+
unsupport_all_notifiers
|
7
|
+
end
|
8
|
+
|
9
|
+
test "return default notifier when is set" do
|
10
|
+
TestNotifier.default_notifier = :osd_cat
|
11
|
+
TestNotifier::Notifier::OsdCat.expects(:supported?).returns(true)
|
12
|
+
|
13
|
+
assert_equal TestNotifier::Notifier::OsdCat, TestNotifier.notifier
|
14
|
+
end
|
15
|
+
|
16
|
+
test "return next available notifier when default notifier is not supported" do
|
17
|
+
TestNotifier.default_notifier = :osd_cat
|
18
|
+
TestNotifier::Notifier::Snarl.expects(:supported?).returns(true)
|
19
|
+
|
20
|
+
assert_equal TestNotifier::Notifier::Snarl, TestNotifier.notifier
|
21
|
+
end
|
22
|
+
|
23
|
+
test "raise error when there's no supported notifier" do
|
24
|
+
assert_raise TestNotifier::UnsupportedNotifierError do
|
25
|
+
TestNotifier.notifier
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "send notification to supported notifier" do
|
30
|
+
TestNotifier::Notifier::Snarl.expects(:supported?).returns(true)
|
31
|
+
TestNotifier::Notifier::Snarl.expects(:notify).with({
|
32
|
+
:status => :fail,
|
33
|
+
:message => "You have failed!",
|
34
|
+
:title => TestNotifier::TITLES[:fail],
|
35
|
+
:image => TestNotifier::IMAGES[:fail]
|
36
|
+
})
|
37
|
+
|
38
|
+
TestNotifier.notify :status => :fail, :message => "You have failed!"
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nando Vieira
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-27 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -53,6 +53,9 @@ files:
|
|
53
53
|
- resources/fail.png
|
54
54
|
- resources/register-growl.scpt
|
55
55
|
- resources/success.png
|
56
|
+
- test/notifier_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
- test/test_notifier_test.rb
|
56
59
|
has_rdoc: true
|
57
60
|
homepage: http://github.com/fnando/test_notifier
|
58
61
|
licenses: []
|
@@ -87,5 +90,7 @@ rubygems_version: 1.3.7
|
|
87
90
|
signing_key:
|
88
91
|
specification_version: 3
|
89
92
|
summary: Display system notifications (dbus, growl and snarl) after running tests.
|
90
|
-
test_files:
|
91
|
-
|
93
|
+
test_files:
|
94
|
+
- test/notifier_test.rb
|
95
|
+
- test/test_helper.rb
|
96
|
+
- test/test_notifier_test.rb
|