libnotify 0.7.0-universal-rubinius-1.2 → 0.7.1-universal-rubinius-1.2

Sign up to get free protection for your applications and to get access to all the features.
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/api.rb CHANGED
@@ -89,6 +89,11 @@ module Libnotify
89
89
  end
90
90
  end
91
91
 
92
+ # Close a previously shown notification.
93
+ def close
94
+ notify_notification_close(@notification, nil) if @notification
95
+ end
96
+
92
97
  # @todo Simplify timeout=
93
98
  def timeout=(timeout)
94
99
  @timeout = case timeout
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)
@@ -1,3 +1,3 @@
1
1
  module Libnotify
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
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/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
@@ -1,121 +1,87 @@
1
1
  require 'helper'
2
2
 
3
- class TestLibnotify < MiniTest::Unit::TestCase
4
- def test_respond_to
5
- assert_respond_to Libnotify, :new
6
- assert_respond_to Libnotify, :show
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
- def test_version
24
- assert defined?(Libnotify::VERSION), "version is defined"
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
- assert_equal "hello", libnotify.summary
49
- assert_equal "overwritten", libnotify.body
50
- assert_equal "/path/to/icon", libnotify.icon_path
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
- def test_integration
84
- skip "enable integration"
85
-
86
- libnotify = Libnotify::API.new(:timeout => 0.5, :icon_path => :"emblem-favorite", :append => true)
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
- [ :low, :normal, :critical ].each do |urgency|
89
- libnotify.summary = "#{RUBY_VERSION} at #{RUBY_PLATFORM}"
90
- libnotify.body = [ urgency, defined?(RUBY_DESCRIPTION) ? RUBY_DESCRIPTION : '?' ].join(" ")
91
- libnotify.urgency = urgency
92
- libnotify.show!
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
- private
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
- def libnotify(options={}, &block)
99
- @libnotify ||= Libnotify::API.new(options, &block)
100
- end
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
- def assert_timeout(expected, value, message)
103
- assert_value_set :timeout, expected, value, message
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
- def assert_icon_path(expected, value, message)
107
- assert_value_set :icon_path, expected, value, message
108
- end
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
- def assert_value_set(attribute, expected, value, message)
111
- libnotify.send("#{attribute}=", value)
112
- got = libnotify.send(attribute)
113
- case expected
114
- when Regexp
115
- assert_match expected, got, message
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
11
11
  platform: universal-rubinius-1.2
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-02 00:00:00 +01:00
18
+ date: 2012-01-04 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency