libnotify 0.7.0 → 0.7.1
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 +3 -1
- data/lib/libnotify.rb +3 -1
- data/lib/libnotify/api.rb +5 -0
- data/lib/libnotify/ffi.rb +1 -0
- data/lib/libnotify/version.rb +1 -1
- data/test/helper.rb +34 -0
- data/test/test_libnotify.rb +67 -101
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -37,13 +37,15 @@ http://github.com/splattael/libnotify/raw/master/libnotify.png
|
|
37
37
|
Libnotify.show(:icon_path => "emblem-default.png")
|
38
38
|
Libnotify.show(:icon_path => :"emblem-default")
|
39
39
|
|
40
|
-
# Update pre-existing notification
|
40
|
+
# Update pre-existing notification then close it
|
41
41
|
n = Libnotify.new(:summary => "hello", :body => "world")
|
42
42
|
n.update # identical to show! if not shown before
|
43
43
|
Kernel.sleep 1
|
44
44
|
n.update(:body => "my love") do |notify|
|
45
45
|
notify.summary = "goodbye"
|
46
46
|
end
|
47
|
+
Kernel.sleep 1
|
48
|
+
n.close
|
47
49
|
|
48
50
|
|
49
51
|
== Installation
|
data/lib/libnotify.rb
CHANGED
@@ -23,13 +23,15 @@ module Libnotify
|
|
23
23
|
# @example Hash syntax
|
24
24
|
# Libnotify.show(:body => "hello", :summary => "world", :timeout => 2.5)
|
25
25
|
#
|
26
|
-
# @example Update pre-existing notification
|
26
|
+
# @example Update pre-existing notification then close it
|
27
27
|
# n = Libnotify.new(:summary => "hello", :body => "world")
|
28
28
|
# n.update # identical to show! if not shown before
|
29
29
|
# Kernel.sleep 1
|
30
30
|
# n.update(:body => "my love") do |notify|
|
31
31
|
# notify.summary = "goodbye"
|
32
32
|
# end
|
33
|
+
# Kernel.sleep 1
|
34
|
+
# n.close
|
33
35
|
#
|
34
36
|
# @example Mixed syntax
|
35
37
|
# Libnotify.new(options) do |n|
|
data/lib/libnotify/api.rb
CHANGED
data/lib/libnotify/ffi.rb
CHANGED
@@ -29,6 +29,7 @@ module Libnotify
|
|
29
29
|
attach_function :notify_notification_set_hint_uint32, [:pointer, :string, :int], :void
|
30
30
|
attach_function :notify_notification_clear_hints, [:pointer], :void
|
31
31
|
attach_function :notify_notification_show, [:pointer, :pointer], :bool
|
32
|
+
attach_function :notify_notification_close, [:pointer, :pointer], :bool
|
32
33
|
end
|
33
34
|
|
34
35
|
def lookup_urgency(urgency)
|
data/lib/libnotify/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -4,3 +4,37 @@ require 'minitest/autorun'
|
|
4
4
|
require 'minitest/libnotify'
|
5
5
|
|
6
6
|
require 'libnotify'
|
7
|
+
|
8
|
+
module LibnotifyAssertions
|
9
|
+
def assert_timeout(expected, value, message)
|
10
|
+
assert_value_set :timeout, expected, value, message
|
11
|
+
end
|
12
|
+
|
13
|
+
def assert_icon_path(expected, value, message)
|
14
|
+
assert_value_set :icon_path, expected, value, message
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_value_set(attribute, expected, value, message)
|
18
|
+
libnotify.send("#{attribute}=", value)
|
19
|
+
got = libnotify.send(attribute)
|
20
|
+
case expected
|
21
|
+
when Regexp
|
22
|
+
assert_match expected, got, message
|
23
|
+
else
|
24
|
+
assert_equal expected, got, message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class LibnotifyTestCase < MiniTest::Spec
|
30
|
+
include LibnotifyAssertions
|
31
|
+
|
32
|
+
class << self
|
33
|
+
alias :test :it
|
34
|
+
alias :context :describe
|
35
|
+
end
|
36
|
+
|
37
|
+
def libnotify(options={}, &block)
|
38
|
+
@libnotify ||= Libnotify::API.new(options, &block)
|
39
|
+
end
|
40
|
+
end
|
data/test/test_libnotify.rb
CHANGED
@@ -1,121 +1,87 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
|
-
class TestLibnotify <
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
|
9
|
-
def test_delegation
|
10
|
-
skip "test delegation using mock"
|
11
|
-
|
12
|
-
# old code
|
13
|
-
asserts("#new calls API#new") do
|
14
|
-
mock(Libnotify::API).new(hash_including(:body => "test")) { true }
|
15
|
-
Libnotify.new(:body => "test")
|
16
|
-
end
|
17
|
-
asserts("#show calls API#show") do
|
18
|
-
mock(Libnotify::API).show(hash_including(:body => "test")) { true }
|
19
|
-
Libnotify.show(:body => "test")
|
3
|
+
class TestLibnotify < LibnotifyTestCase
|
4
|
+
context Libnotify do
|
5
|
+
test "responds to new" do
|
6
|
+
assert_respond_to Libnotify, :new
|
20
7
|
end
|
21
|
-
end
|
22
8
|
|
23
|
-
|
24
|
-
|
25
|
-
assert Libnotify::VERSION
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class TestLibnotifyAPI < MiniTest::Unit::TestCase
|
30
|
-
def test_without_options_and_block
|
31
|
-
assert_equal " ", libnotify.summary
|
32
|
-
assert_equal " ", libnotify.body
|
33
|
-
assert_equal :normal, libnotify.urgency
|
34
|
-
assert_nil libnotify.timeout
|
35
|
-
assert_nil libnotify.icon_path
|
36
|
-
assert libnotify.append
|
37
|
-
assert !libnotify.transient
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_with_options_and_block
|
41
|
-
libnotify(:summary => "hello", :body => "body", :invalid_option => 23) do |n|
|
42
|
-
n.body = "overwritten"
|
43
|
-
n.icon_path = "/path/to/icon"
|
44
|
-
n.append = false
|
45
|
-
n.transient = true
|
9
|
+
test "responds to show" do
|
10
|
+
assert_respond_to Libnotify, :show
|
46
11
|
end
|
47
12
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
assert !libnotify.append
|
52
|
-
assert libnotify.transient
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_timeout_setter
|
56
|
-
assert_timeout 2500, 2.5, "with float"
|
57
|
-
assert_timeout 100, 100, "with fixnum ms"
|
58
|
-
assert_timeout 101, 101, "with fixnum ms"
|
59
|
-
assert_timeout 1000, 1, "with fixnum seconds"
|
60
|
-
assert_timeout 99000, 99, "with fixnum seconds"
|
61
|
-
assert_timeout nil, nil, "with nil"
|
62
|
-
assert_timeout nil, false, "with false"
|
63
|
-
assert_timeout 2, :"2 s", "with to_s.to_i"
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_icon_path_setter
|
67
|
-
Libnotify::API.icon_dirs << File.expand_path("../..", __FILE__)
|
68
|
-
assert_icon_path "/some/path/image.jpg", "/some/path/image.jpg", "with absolute path"
|
69
|
-
assert_icon_path "some-invalid-path.jpg", "some-invalid-path.jpg", "with non-existant relative path"
|
70
|
-
assert_icon_path %r{^/.*/libnotify.png}, "libnotify.png", "with relative path"
|
71
|
-
assert_icon_path %r{^/.*/libnotify.png}, :"libnotify", "with symbol"
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_update
|
75
|
-
libnotify(:summary => "hello", :body => "world").show!
|
76
|
-
libnotify.update(:summary => "hell") do |n|
|
77
|
-
n.body = "yeah"
|
13
|
+
test "has version" do
|
14
|
+
assert defined?(Libnotify::VERSION), "version is defined"
|
15
|
+
assert Libnotify::VERSION
|
78
16
|
end
|
79
|
-
assert_equal "hell", libnotify.summary
|
80
|
-
assert_equal "yeah", libnotify.body
|
81
17
|
end
|
82
18
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
19
|
+
context Libnotify::API do
|
20
|
+
test "instance default values" do
|
21
|
+
assert_equal " ", libnotify.summary
|
22
|
+
assert_equal " ", libnotify.body
|
23
|
+
assert_equal :normal, libnotify.urgency
|
24
|
+
assert_nil libnotify.timeout
|
25
|
+
assert_nil libnotify.icon_path
|
26
|
+
assert libnotify.append
|
27
|
+
refute libnotify.transient
|
28
|
+
end
|
87
29
|
|
88
|
-
|
89
|
-
libnotify
|
90
|
-
|
91
|
-
|
92
|
-
|
30
|
+
test "instance with options and block" do
|
31
|
+
libnotify(:summary => "hello", :body => "body", :invalid_option => 23) do |n|
|
32
|
+
n.body = "overwritten"
|
33
|
+
n.icon_path = "/path/to/icon"
|
34
|
+
n.append = false
|
35
|
+
n.transient = true
|
36
|
+
end
|
37
|
+
|
38
|
+
assert_equal "hello", libnotify.summary
|
39
|
+
assert_equal "overwritten", libnotify.body
|
40
|
+
assert_equal "/path/to/icon", libnotify.icon_path
|
41
|
+
refute libnotify.append
|
42
|
+
assert libnotify.transient
|
93
43
|
end
|
94
|
-
end
|
95
44
|
|
96
|
-
|
45
|
+
test "timeout=" do
|
46
|
+
assert_timeout 2500, 2.5, "with float"
|
47
|
+
assert_timeout 100, 100, "with fixnum ms"
|
48
|
+
assert_timeout 101, 101, "with fixnum ms"
|
49
|
+
assert_timeout 1000, 1, "with fixnum seconds"
|
50
|
+
assert_timeout 99000, 99, "with fixnum seconds"
|
51
|
+
assert_timeout nil, nil, "with nil"
|
52
|
+
assert_timeout nil, false, "with false"
|
53
|
+
assert_timeout 2, :"2 s", "with to_s.to_i"
|
54
|
+
end
|
97
55
|
|
98
|
-
|
99
|
-
|
100
|
-
|
56
|
+
test "icon_path=" do
|
57
|
+
Libnotify::API.icon_dirs << File.expand_path("../..", __FILE__)
|
58
|
+
assert_icon_path "/some/path/image.jpg", "/some/path/image.jpg", "with absolute path"
|
59
|
+
assert_icon_path "some-invalid-path.jpg", "some-invalid-path.jpg", "with non-existant relative path"
|
60
|
+
assert_icon_path %r{^/.*/libnotify.png}, "libnotify.png", "with relative path"
|
61
|
+
assert_icon_path %r{^/.*/libnotify.png}, :"libnotify", "with symbol"
|
62
|
+
end
|
101
63
|
|
102
|
-
|
103
|
-
|
64
|
+
test "update" do
|
65
|
+
libnotify(:summary => "hello", :body => "world").show!
|
66
|
+
libnotify.update(:summary => "hell") do |n|
|
67
|
+
n.body = "yeah"
|
68
|
+
end
|
69
|
+
assert_equal "hell", libnotify.summary
|
70
|
+
assert_equal "yeah", libnotify.body
|
71
|
+
libnotify.close
|
72
|
+
end
|
104
73
|
end
|
105
74
|
|
106
|
-
|
107
|
-
|
108
|
-
|
75
|
+
context "integration" do
|
76
|
+
test "works" do
|
77
|
+
libnotify = Libnotify::API.new(:timeout => 0.5, :icon_path => :"emblem-favorite", :append => true)
|
109
78
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
else
|
117
|
-
assert_equal expected, got, message
|
79
|
+
[ :low, :normal, :critical ].each do |urgency|
|
80
|
+
libnotify.summary = "#{RUBY_VERSION} at #{RUBY_PLATFORM}"
|
81
|
+
libnotify.body = [ urgency, defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : '?' ].join(" ")
|
82
|
+
libnotify.urgency = urgency
|
83
|
+
libnotify.show!
|
84
|
+
end
|
118
85
|
end
|
119
86
|
end
|
120
|
-
|
121
87
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libnotify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Suschlik
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-
|
18
|
+
date: 2012-01-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: ffi
|