notifiers 1.2.1 → 2.0.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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Notifiers
@@ -8,98 +10,154 @@ module Notifiers
8
10
  @notify_send = notify_send
9
11
  end
10
12
 
13
+ describe '.installed?' do
14
+ context 'when is linux or freebsd platform' do
15
+ before do
16
+ expect(NotifySend).to receive(:platform?).with(/(freebsd|linux)/).and_return(true)
17
+ end
18
+
19
+ context 'with notify-send installed' do
20
+ before do
21
+ expect(NotifySend).to receive(:command?).with('notify-send').and_return(true)
22
+ end
23
+
24
+ it 'returns true' do
25
+ expect(NotifySend).to be_installed
26
+ end
27
+ end
28
+
29
+ context 'without notify-send installed' do
30
+ before do
31
+ expect(NotifySend).to receive(:command?).with('notify-send').and_return(false)
32
+ end
33
+
34
+ it 'returns false' do
35
+ expect(NotifySend).to_not be_installed
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'when is not linux or freebsd platform' do
41
+ before do
42
+ expect(NotifySend).to receive(:platform?).with(/(freebsd|linux)/).and_return(false)
43
+ end
44
+
45
+ it 'returns false' do
46
+ expect(NotifySend).to_not be_installed
47
+ end
48
+ end
49
+ end
50
+
11
51
  describe '#image' do
12
- it "should set the image" do
52
+ it 'sets the image' do
13
53
  @notify_send.image('my_image.png')
14
54
  expect(@notify_send.instance_variable_get(:@icon)).to eql 'my_image.png'
15
55
  end
16
56
 
17
- it "should set the icon option" do
57
+ it 'sets the icon option' do
18
58
  @notify_send.image('homer_simpson.png')
19
59
  expect(@notify_send.instance_variable_get(:@icon)).to eql 'homer_simpson.png'
20
60
  end
21
61
  end
22
62
 
23
63
  describe '#message' do
24
- it "should set the message" do
64
+ it 'sets the message' do
25
65
  @notify_send.message('Oh Donuts!')
26
66
  expect(@notify_send.instance_variable_get(:@message)).to eql 'Oh Donuts!'
27
67
  end
28
68
 
29
- it "should set the message option" do
69
+ it 'sets the message option' do
30
70
  @notify_send.message('Duff Beer')
31
71
  expect(@notify_send.instance_variable_get(:@message)).to eql 'Duff Beer'
32
72
  end
33
73
  end
34
74
 
35
75
  describe '#title' do
36
- it "should set the title" do
76
+ it 'sets the title' do
37
77
  @notify_send.title('W00T!!')
38
78
  expect(@notify_send.instance_variable_get(:@title)).to eql 'W00T!!'
39
79
  end
40
80
 
41
- it "should set a title as intance variable" do
81
+ it 'sets a title as instance variable' do
42
82
  @notify_send.title('Joker Owned Batman!')
43
83
  expect(@notify_send.instance_variable_get(:@title)).to eql 'Joker Owned Batman!'
44
84
  end
45
85
  end
46
86
 
47
87
  describe '#urgency' do
48
- it "should set the urgency instance variable to low" do
88
+ it 'sets the urgency instance variable to low' do
49
89
  @notify_send.urgency(:low)
50
90
  expect(@notify_send.instance_variable_get(:@urgency)).to eql 'low'
51
91
  end
52
92
 
53
- it "should set he urgency instance variable to normal" do
93
+ it 'sets the urgency instance variable to normal' do
54
94
  @notify_send.urgency(:normal)
55
95
  expect(@notify_send.instance_variable_get(:@urgency)).to eql 'normal'
56
96
  end
57
97
 
58
- it "should set the urgency to critical" do
98
+ it 'sets the urgency to critical' do
59
99
  @notify_send.urgency(:critical)
60
100
  expect(@notify_send.instance_variable_get(:@urgency)).to eql 'critical'
61
101
  end
62
102
  end
63
103
 
64
104
  describe '#expire_time' do
65
- it "should set the expire time" do
105
+ it 'sets the expire time' do
66
106
  @notify_send.expire_time(1000)
67
107
  expect(@notify_send.instance_variable_get(:@expire_time)).to eql 1000
68
108
  end
69
109
 
70
- it "should set the expire time in miliseconds" do
110
+ it 'sets the expire time in milliseconds' do
71
111
  @notify_send.expire_time(2000)
72
112
  expect(@notify_send.instance_variable_get(:@expire_time)).to eql 2000
73
113
  end
74
114
  end
75
115
 
76
116
  describe '#hint' do
77
- it "should set the hint" do
117
+ it 'sets the hint' do
78
118
  @notify_send.hint([:string, :me, :yeah])
79
119
  expect(@notify_send.instance_variable_get(:@hint)).to eql 'string:me:yeah'
80
120
  end
81
121
 
82
- it "should set the hint in int" do
122
+ it 'sets the hint in int' do
83
123
  @notify_send.hint([:int, :me, 1])
84
124
  expect(@notify_send.instance_variable_get(:@hint)).to eql 'int:me:1'
85
125
  end
86
126
  end
87
127
 
128
+ describe '#category' do
129
+ it 'sets the category' do
130
+ @notify_send.category('email')
131
+ expect(@notify_send.instance_variable_get(:@category)).to eql 'email'
132
+ end
133
+ end
134
+
88
135
  describe '#to_s' do
89
- it "should transform in a command" do
136
+ it 'transforms in a command' do
90
137
  command = @notify_send.title('Inception').message('3 levels').image('my_image.png').to_s
91
138
  expect(command).to eql "notify-send --icon=my_image.png 'Inception' '3 levels'"
92
139
  end
93
140
 
94
- it "should transform in a command to execute" do
141
+ it 'transforms in a command with hint and expire_time' do
95
142
  command = @notify_send.title('Joker').message('Haha ha!').expire_time(1000).hint([:string, :me, :woot]).to_s
96
- expect(command).to eql "notify-send --hint=string:me:woot --expire-time=1000 'Joker' 'Haha ha!'"
143
+ expect(command).to eql "notify-send --expire-time=1000 --hint=string:me:woot 'Joker' 'Haha ha!'"
97
144
  end
98
145
 
99
- it "should transform in a command to execute" do
146
+ it 'transforms in a command with urgency' do
100
147
  command = @notify_send.title('Batman').urgency(:critical).to_s
101
148
  expect(command).to eql "notify-send --urgency=critical 'Batman'"
102
149
  end
150
+
151
+ it 'transforms in a command with category' do
152
+ command = @notify_send.title('Mail').message('New email').category('email').to_s
153
+ expect(command).to eql "notify-send --category=email 'Mail' 'New email'"
154
+ end
155
+ end
156
+
157
+ describe '#install_instructions' do
158
+ it 'returns installation instructions' do
159
+ expect(@notify_send.install_instructions).to eq 'notify-send is not installed. Install libnotify for your distribution.'
160
+ end
103
161
  end
104
162
  end
105
163
  end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Notifiers
6
+ describe Osascript do
7
+ it_should_behave_like 'a notifier'
8
+
9
+ before do
10
+ @osascript = osascript
11
+ end
12
+
13
+ describe '.installed?' do
14
+ context 'when is darwin platform' do
15
+ before do
16
+ expect(Osascript).to receive(:platform?).with(/darwin/).and_return(true)
17
+ end
18
+
19
+ context 'with osascript installed' do
20
+ before do
21
+ expect(Osascript).to receive(:command?).with('osascript').and_return(true)
22
+ end
23
+
24
+ it 'returns true' do
25
+ expect(Osascript).to be_installed
26
+ end
27
+ end
28
+
29
+ context 'without osascript installed' do
30
+ before do
31
+ expect(Osascript).to receive(:command?).with('osascript').and_return(false)
32
+ end
33
+
34
+ it 'returns false' do
35
+ expect(Osascript).to_not be_installed
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'when is not darwin platform' do
41
+ before do
42
+ expect(Osascript).to receive(:platform?).with(/darwin/).and_return(false)
43
+ end
44
+
45
+ it 'returns false' do
46
+ expect(Osascript).to_not be_installed
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#message' do
52
+ it 'sets the message' do
53
+ @osascript.message('Hello World!')
54
+ expect(@osascript.instance_variable_get(:@message)).to eql 'Hello World!'
55
+ end
56
+ end
57
+
58
+ describe '#title' do
59
+ it 'sets the title' do
60
+ @osascript.title('My App')
61
+ expect(@osascript.instance_variable_get(:@title)).to eql 'My App'
62
+ end
63
+ end
64
+
65
+ describe '#subtitle' do
66
+ it 'sets the subtitle' do
67
+ @osascript.subtitle('Additional info')
68
+ expect(@osascript.instance_variable_get(:@subtitle)).to eql 'Additional info'
69
+ end
70
+ end
71
+
72
+ describe '#sound' do
73
+ it 'sets the sound' do
74
+ @osascript.sound('default')
75
+ expect(@osascript.instance_variable_get(:@sound)).to eql 'default'
76
+ end
77
+
78
+ it 'sets a custom sound' do
79
+ @osascript.sound('Glass')
80
+ expect(@osascript.instance_variable_get(:@sound)).to eql 'Glass'
81
+ end
82
+ end
83
+
84
+ describe '#to_s' do
85
+ it 'constructs the command with message only' do
86
+ command = @osascript.message('Hello World!').to_s
87
+ expect(command).to eql "osascript -e 'display notification \"Hello World!\"'"
88
+ end
89
+
90
+ it 'constructs the command with title and message' do
91
+ command = @osascript.title('Test').message('Hello World!').to_s
92
+ expect(command).to eql "osascript -e 'display notification \"Hello World!\" with title \"Test\"'"
93
+ end
94
+
95
+ it 'constructs the command with subtitle' do
96
+ command = @osascript.title('Test').subtitle('Info').message('Hello').to_s
97
+ expect(command).to eql "osascript -e 'display notification \"Hello\" with title \"Test\" subtitle \"Info\"'"
98
+ end
99
+
100
+ it 'constructs the command with sound' do
101
+ command = @osascript.message('Alert').sound('Glass').to_s
102
+ expect(command).to eql "osascript -e 'display notification \"Alert\" sound name \"Glass\"'"
103
+ end
104
+
105
+ it 'constructs the full command' do
106
+ command = @osascript.title('App').subtitle('Status').message('Done').sound('default').to_s
107
+ expect(command).to eql "osascript -e 'display notification \"Done\" with title \"App\" subtitle \"Status\" sound name \"default\"'"
108
+ end
109
+ end
110
+
111
+ describe '#install_instructions' do
112
+ it 'returns empty string since osascript is built-in' do
113
+ expect(@osascript.install_instructions).to eq ''
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ module Notifiers
6
+ describe TerminalNotifier do
7
+ it_should_behave_like 'a notifier'
8
+
9
+ before do
10
+ @terminal_notifier = terminal_notifier
11
+ end
12
+
13
+ describe '.installed?' do
14
+ context 'when is darwin platform' do
15
+ before do
16
+ expect(TerminalNotifier).to receive(:platform?).with(/darwin/).and_return(true)
17
+ end
18
+
19
+ context 'with terminal-notifier installed' do
20
+ before do
21
+ expect(TerminalNotifier).to receive(:command?).with('terminal-notifier').and_return(true)
22
+ end
23
+
24
+ it 'returns true' do
25
+ expect(TerminalNotifier).to be_installed
26
+ end
27
+ end
28
+
29
+ context 'without terminal-notifier installed' do
30
+ before do
31
+ expect(TerminalNotifier).to receive(:command?).with('terminal-notifier').and_return(false)
32
+ end
33
+
34
+ it 'returns false' do
35
+ expect(TerminalNotifier).to_not be_installed
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'when is not darwin platform' do
41
+ before do
42
+ expect(TerminalNotifier).to receive(:platform?).with(/darwin/).and_return(false)
43
+ end
44
+
45
+ it 'returns false' do
46
+ expect(TerminalNotifier).to_not be_installed
47
+ end
48
+ end
49
+ end
50
+
51
+ describe '#image' do
52
+ it 'sets the icon' do
53
+ @terminal_notifier.image('my_image.png')
54
+ expect(@terminal_notifier.instance_variable_get(:@icon)).to eql 'my_image.png'
55
+ end
56
+ end
57
+
58
+ describe '#message' do
59
+ it 'sets the message' do
60
+ @terminal_notifier.message('Hello World!')
61
+ expect(@terminal_notifier.instance_variable_get(:@message)).to eql 'Hello World!'
62
+ end
63
+ end
64
+
65
+ describe '#title' do
66
+ it 'sets the title' do
67
+ @terminal_notifier.title('My App')
68
+ expect(@terminal_notifier.instance_variable_get(:@title)).to eql 'My App'
69
+ end
70
+ end
71
+
72
+ describe '#sound' do
73
+ it 'sets the sound' do
74
+ @terminal_notifier.sound('default')
75
+ expect(@terminal_notifier.instance_variable_get(:@sound)).to eql 'default'
76
+ end
77
+
78
+ it 'sets a custom sound' do
79
+ @terminal_notifier.sound('Ping')
80
+ expect(@terminal_notifier.instance_variable_get(:@sound)).to eql 'Ping'
81
+ end
82
+ end
83
+
84
+ describe '#group' do
85
+ it 'sets the group' do
86
+ @terminal_notifier.group('my-group')
87
+ expect(@terminal_notifier.instance_variable_get(:@group)).to eql 'my-group'
88
+ end
89
+ end
90
+
91
+ describe '#open' do
92
+ it 'sets the url to open' do
93
+ @terminal_notifier.open('https://example.com')
94
+ expect(@terminal_notifier.instance_variable_get(:@open)).to eql 'https://example.com'
95
+ end
96
+ end
97
+
98
+ describe '#execute' do
99
+ it 'sets the command to execute' do
100
+ @terminal_notifier.execute('open .')
101
+ expect(@terminal_notifier.instance_variable_get(:@execute)).to eql 'open .'
102
+ end
103
+ end
104
+
105
+ describe '#to_s' do
106
+ it 'constructs the command with title and message' do
107
+ command = @terminal_notifier.title('Test').message('Hello World!').to_s
108
+ expect(command).to eql "terminal-notifier -title 'Test' -message 'Hello World!'"
109
+ end
110
+
111
+ it 'constructs the command with image and sound' do
112
+ command = @terminal_notifier.message('Alert').image('icon.png').sound('default').to_s
113
+ expect(command).to eql "terminal-notifier -message 'Alert' -contentImage 'icon.png' -sound 'default'"
114
+ end
115
+
116
+ it 'constructs the command with group and open' do
117
+ command = @terminal_notifier.message('Click me').group('notifications').open('https://example.com').to_s
118
+ expect(command).to eql "terminal-notifier -message 'Click me' -group 'notifications' -open 'https://example.com'"
119
+ end
120
+
121
+ it 'constructs the command with execute' do
122
+ command = @terminal_notifier.message('Run').execute('open .').to_s
123
+ expect(command).to eql "terminal-notifier -message 'Run' -execute 'open .'"
124
+ end
125
+ end
126
+
127
+ describe '#install_instructions' do
128
+ it 'returns installation instructions' do
129
+ expect(@terminal_notifier.install_instructions).to eq 'terminal-notifier is not installed. Install with: brew install terminal-notifier'
130
+ end
131
+ end
132
+ end
133
+ end
@@ -1,19 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Notifiers do
4
- it { expect(growl).to be_instance_of(Notifiers::Growl) }
6
+ it { expect(terminal_notifier).to be_instance_of(Notifiers::TerminalNotifier) }
5
7
 
6
- it { expect(knotify).to be_instance_of(Notifiers::Knotify) }
8
+ it { expect(osascript).to be_instance_of(Notifiers::Osascript) }
7
9
 
8
10
  it { expect(notify_send).to be_instance_of(Notifiers::NotifySend) }
9
11
 
10
12
  it { expect(lib_notify).to be_instance_of(Notifiers::NotifySend) }
11
13
 
14
+ it { expect(dunstify).to be_instance_of(Notifiers::Dunstify) }
15
+
12
16
  describe '#auto_discover' do
13
17
  context 'when have a notifier library installed' do
14
18
  it 'returns the notifier' do
15
- expect(Notifiers::Growl).to receive(:installed?).and_return(true)
16
- expect(auto_discover).to be_instance_of(Notifiers::Growl)
19
+ expect(Notifiers::TerminalNotifier).to receive(:installed?).and_return(true)
20
+ expect(auto_discover).to be_instance_of(Notifiers::TerminalNotifier)
17
21
  end
18
22
  end
19
23
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  require 'notifiers'
3
5
 
metadata CHANGED
@@ -1,54 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás D'Stefano
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2014-02-05 00:00:00.000000000 Z
10
+ date: 2026-02-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rspec
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ~>
16
+ - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '2.14'
18
+ version: '3.13'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - ~>
23
+ - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '2.14'
25
+ version: '3.13'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: bundler
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - '>='
30
+ - - ">="
32
31
  - !ruby/object:Gem::Version
33
- version: 1.0.0
32
+ version: '2.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - '>='
37
+ - - ">="
39
38
  - !ruby/object:Gem::Version
40
- version: 1.0.0
41
- description: Use Growl and Lib-Notify in a simple and clean way.
39
+ version: '2.0'
40
+ description: Send desktop notifications on macOS (terminal-notifier, osascript) and
41
+ Linux (notify-send, dunstify) in a simple and clean way.
42
42
  email:
43
43
  - tomasdestefi@gmail.com
44
44
  executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
49
- - .infinity_test
50
- - .rspec
51
- - .travis.yml
48
+ - ".github/workflows/ci.yml"
49
+ - ".gitignore"
50
+ - ".infinity_test"
51
+ - ".rspec"
52
52
  - Gemfile
53
53
  - History.markdown
54
54
  - README.markdown
@@ -56,38 +56,38 @@ files:
56
56
  - TODO.markdown
57
57
  - lib/notifiers.rb
58
58
  - lib/notifiers/base.rb
59
- - lib/notifiers/growl.rb
60
- - lib/notifiers/knotify.rb
59
+ - lib/notifiers/dunstify.rb
61
60
  - lib/notifiers/notifier_not_found.rb
62
61
  - lib/notifiers/notify_send.rb
62
+ - lib/notifiers/osascript.rb
63
+ - lib/notifiers/terminal_notifier.rb
63
64
  - notifiers.gemspec
64
65
  - spec/notifiers/base_spec.rb
65
- - spec/notifiers/growl_spec.rb
66
- - spec/notifiers/knotify_spec.rb
66
+ - spec/notifiers/dunstify_spec.rb
67
67
  - spec/notifiers/notify_send_spec.rb
68
+ - spec/notifiers/osascript_spec.rb
69
+ - spec/notifiers/terminal_notifier_spec.rb
68
70
  - spec/notifiers_spec.rb
69
71
  - spec/spec_helper.rb
70
- homepage: http://rubygems.org/gems/notifiers
71
- licenses: []
72
+ homepage: https://rubygems.org/gems/notifiers
73
+ licenses:
74
+ - MIT
72
75
  metadata: {}
73
- post_install_message:
74
76
  rdoc_options: []
75
77
  require_paths:
76
78
  - lib
77
79
  required_ruby_version: !ruby/object:Gem::Requirement
78
80
  requirements:
79
- - - '>='
81
+ - - ">="
80
82
  - !ruby/object:Gem::Version
81
- version: '0'
83
+ version: '3.0'
82
84
  required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  requirements:
84
- - - '>='
86
+ - - ">="
85
87
  - !ruby/object:Gem::Version
86
- version: 1.3.6
88
+ version: '3.0'
87
89
  requirements: []
88
- rubyforge_project: notifiers
89
- rubygems_version: 2.0.5
90
- signing_key:
90
+ rubygems_version: 3.6.2
91
91
  specification_version: 4
92
- summary: Use notifications in a simple and elegant way.
92
+ summary: Cross-platform desktop notifications for macOS and Linux.
93
93
  test_files: []
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - jruby
5
- - 2.0
6
- before_install:
7
- - export DISPLAY=:99.0
8
- - sh -e /etc/init.d/xvfb start
9
- script:
10
- - bundle exec rspec
@@ -1,47 +0,0 @@
1
- module Notifiers
2
- class Growl < Notifiers::Base
3
- def self.installed?
4
- darwin? and command?('growlnotify')
5
- end
6
-
7
- def image(icon)
8
- @image = icon
9
- self
10
- end
11
-
12
- def priority(number)
13
- @priority = number
14
- self
15
- end
16
-
17
- def host(hostname)
18
- @host = hostname
19
- self
20
- end
21
-
22
- def password(secret)
23
- @password = secret
24
- self
25
- end
26
-
27
- def auth(authentication)
28
- @auth = authentication
29
- self
30
- end
31
-
32
- def to_s
33
- command = 'growlnotify'
34
- command << " --title '#{@title}'" if @title
35
- command << " --message '#{@message}'"
36
- [:image, :priority, :host, :password, :auth].each do |option|
37
- variable = instance_variable_get("@#{option}")
38
- command << " --#{option} #{variable}" if variable
39
- end
40
- command
41
- end
42
-
43
- def install_instructions
44
- 'The Growl is not installed. You can find more details here: http://growl.info/downloads'
45
- end
46
- end
47
- end
@@ -1,14 +0,0 @@
1
- module Notifiers
2
- class Knotify < Notifiers::Base
3
- COMMAND = "dcop knotify default notify eventname"
4
-
5
- def to_s
6
- command = "#{COMMAND}"
7
- command << " '#{@title}'" if @title
8
- command << " '#{@message}'" if @message
9
- command << " '' ''"
10
- command << " 12 1"
11
- command
12
- end
13
- end
14
- end