notifiers 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a9805f03cbef83bc8a4adb74e42c2a355d4944e
4
- data.tar.gz: c41421a3c1e48cdf0fc6d5e2d44dd4a2d2d5d44e
3
+ metadata.gz: e3ab9d583cfca62be7ae6a684c9ad504c313c40c
4
+ data.tar.gz: b9c211cbeae8b427040d14d6c387f21cc3a37046
5
5
  SHA512:
6
- metadata.gz: 9b46e6f3cbff9b5ad9c0d83dc58b2625a07a5e57f04fc92c7654dce862a7847520474545c19101a16df48833a38034c459171e5677ff588a95b86d4304a5752a
7
- data.tar.gz: 0bddc7d9c059a4e65a3b821a26806063ac744d9b29369b0a4b002d7c665b5031f79c1159177ae203b01d51e90dbac3059ed003a687c2da11a006374d08c131b5
6
+ metadata.gz: d2f7b8fdaf4b9f7d30ad573451991800f9f043c0cfbfe902c5fef39bbbb199b857f91c1e4e9eafdd52258143e7e19a80aaa8e0c96b5d4f3180c1c053ef17e2f6
7
+ data.tar.gz: a2d9bfd767396565d3e57a7d54d2f6604ce68fec29ac03d72b2829ad46533defa54b07fe7cb51f05f87482624cc5916fb76d801035eff8f8b5690c5a10473a2e
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
- .ruby-version
4
+ .ruby-version
5
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
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
data/History.markdown CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.2.1
2
+
3
+ * Implementing auto discover, just for Growl now.
4
+
5
+ # 1.2.0
6
+
7
+ * When the Growl notify command doesn't exist, show a better error message.
8
+
1
9
  # 1.1.0
2
10
 
3
11
  * Add knotify to notifications message
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Notifiers
2
2
 
3
- Use notifications systems like growlm kib-notify in a simple and elegant way. :)
3
+ Use notifications systems like growl, lib-notify in a simple and elegant way. :)
4
4
 
5
5
  ## Install
6
6
 
data/TODO.markdown CHANGED
@@ -1 +1,2 @@
1
- * When the notifer command doesn't exists, show a better error message.
1
+
2
+ * Auto Discover the OS and notify as expected.
data/lib/notifiers.rb CHANGED
@@ -1,9 +1,8 @@
1
- [ :growl, :knotify, :notify_send].each do |notifier|
1
+ [:base, :growl, :knotify, :notify_send, :notifier_not_found].each do |notifier|
2
2
  require "notifiers/#{notifier}"
3
3
  end
4
4
 
5
5
  module Notifiers
6
-
7
6
  def growl
8
7
  Growl.new
9
8
  end
@@ -16,4 +15,10 @@ module Notifiers
16
15
  NotifySend.new
17
16
  end
18
17
  alias :lib_notify :notify_send
18
+
19
+ def auto_discover
20
+ notifier = Notifiers::Base.subclasses.find { |notifier| notifier.installed? } or raise NotifierNotFound
21
+
22
+ notifier.new
23
+ end
19
24
  end
@@ -0,0 +1,57 @@
1
+ module Notifiers
2
+ class Base
3
+ def self.inherited(subclass)
4
+ @subclasses ||= []
5
+ @subclasses.push(subclass)
6
+ @subclasses
7
+ end
8
+
9
+ def self.subclasses
10
+ @subclasses
11
+ end
12
+
13
+ def self.installed?
14
+ false
15
+ end
16
+
17
+ def self.darwin?
18
+ platform?(/darwin/)
19
+ end
20
+
21
+ def self.platform?(name)
22
+ RbConfig::CONFIG['host_os'] =~ name or RUBY_PLATFORM =~ name
23
+ end
24
+
25
+ def self.command?(command)
26
+ `which #{command}` and $?.zero?
27
+ end
28
+
29
+ def notify
30
+ notification = system(to_s)
31
+
32
+ puts install_instructions unless notification or install_instructions.empty?
33
+
34
+ notification
35
+ end
36
+ alias :notify! :notify
37
+
38
+ def message(text)
39
+ @message = text
40
+ self
41
+ end
42
+
43
+ def title(text)
44
+ @title = text
45
+ self
46
+ end
47
+
48
+ def image(icon)
49
+ @icon = icon
50
+ self
51
+ end
52
+
53
+ def install_instructions
54
+ ''
55
+ end
56
+ end
57
+ end
@@ -1,55 +1,47 @@
1
- class Growl
2
- COMMAND = 'growlnotify'
3
- ERROR_MESSAGE = "The Growl is not installed. You can find more details here:
4
- http://growl.info/downloads"
5
-
6
- def image(icon)
7
- @image = icon
8
- self
9
- end
10
-
11
- def title(text)
12
- @title = text
13
- self
14
- end
1
+ module Notifiers
2
+ class Growl < Notifiers::Base
3
+ def self.installed?
4
+ darwin? and command?('growlnotify')
5
+ end
15
6
 
16
- def message(text)
17
- @message = text
18
- self
19
- end
7
+ def image(icon)
8
+ @image = icon
9
+ self
10
+ end
20
11
 
21
- def priority(number)
22
- @priority = number
23
- self
24
- end
12
+ def priority(number)
13
+ @priority = number
14
+ self
15
+ end
25
16
 
26
- def host(hostname)
27
- @host = hostname
28
- self
29
- end
17
+ def host(hostname)
18
+ @host = hostname
19
+ self
20
+ end
30
21
 
31
- def password(secret)
32
- @password = secret
33
- self
34
- end
22
+ def password(secret)
23
+ @password = secret
24
+ self
25
+ end
35
26
 
36
- def auth(authentication)
37
- @auth = authentication
38
- self
39
- end
27
+ def auth(authentication)
28
+ @auth = authentication
29
+ self
30
+ end
40
31
 
41
- def to_s
42
- command = COMMAND.clone
43
- command << " --title '#{@title}'" if @title
44
- command << " --message '#{@message}'"
45
- [:image, :priority, :host, :password, :auth].each do |option|
46
- variable = instance_variable_get("@#{option}")
47
- command << " --#{option} #{variable}" if variable
48
- end
49
- command
50
- end
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
51
42
 
52
- def notify!
53
- puts ERROR_MESSAGE unless system(to_s)
43
+ def install_instructions
44
+ 'The Growl is not installed. You can find more details here: http://growl.info/downloads'
45
+ end
54
46
  end
55
47
  end
@@ -1,26 +1,14 @@
1
- class Knotify
2
- COMMAND = "dcop knotify default notify eventname"
3
-
4
- def message(text)
5
- @message = text
6
- self
7
- end
8
-
9
- def title(text)
10
- @title = text
11
- self
12
- end
13
-
14
- def to_s
15
- command = "#{COMMAND}"
16
- command << " '#{@title}'" if @title
17
- command << " '#{@message}'" if @message
18
- command << " '' ''"
19
- command << " 12 1"
20
- command
21
- end
22
-
23
- def notify!
24
- system(to_s)
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
25
13
  end
26
14
  end
@@ -0,0 +1,4 @@
1
+ module Notifiers
2
+ class NotifierNotFound < StandardError
3
+ end
4
+ end
@@ -1,53 +1,34 @@
1
- class NotifySend
2
- COMMAND = 'notify-send'
1
+ module Notifiers
2
+ class NotifySend < Notifiers::Base
3
+ COMMAND = 'notify-send'
3
4
 
4
- def message(text)
5
- @message = text
6
- self
7
- end
8
-
9
- def title(text)
10
- @title = text
11
- self
12
- end
13
-
14
- def image(icon)
15
- @icon = icon
16
- self
17
- end
18
-
19
- def urgency(level)
20
- @urgency = level.to_s
21
- self
22
- end
23
-
24
- def expire_time(time)
25
- @expire_time = time
26
- self
27
- end
28
-
29
- def hint(values)
30
- @hint = values.collect.each { |element| element.to_s}.join(':')
31
- self
32
- end
5
+ def urgency(level)
6
+ @urgency = level.to_s
7
+ self
8
+ end
33
9
 
34
- def to_s
35
- command = COMMAND.clone
36
- [:hint, :priority, :icon, :urgency].each do |option|
37
- variable = instance_variable_get("@#{option}")
38
- command << " --#{option}=#{variable}" if variable
10
+ def expire_time(time)
11
+ @expire_time = time
12
+ self
39
13
  end
40
- command << " --expire-time=#{@expire_time}" if @expire_time
41
- [:title, :message].each do |option|
42
- variable = instance_variable_get("@#{option}")
43
- command << " '#{variable}'" if variable
14
+
15
+ def hint(values)
16
+ @hint = values.collect.each { |element| element.to_s}.join(':')
17
+ self
44
18
  end
45
- command
46
- end
47
19
 
48
- # Extract this to a module or something
49
- def notify!
50
- system(to_s)
20
+ def to_s
21
+ command = COMMAND.clone
22
+ [:hint, :priority, :icon, :urgency].each do |option|
23
+ variable = instance_variable_get("@#{option}")
24
+ command << " --#{option}=#{variable}" if variable
25
+ end
26
+ command << " --expire-time=#{@expire_time}" if @expire_time
27
+ [:title, :message].each do |option|
28
+ variable = instance_variable_get("@#{option}")
29
+ command << " '#{variable}'" if variable
30
+ end
31
+ command
32
+ end
51
33
  end
52
-
53
34
  end
data/notifiers.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "notifiers"
5
- s.version = '1.2.0'
5
+ s.version = '1.2.1'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Tomás D'Stefano"]
8
8
  s.email = ["tomasdestefi@gmail.com"]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
14
  s.rubyforge_project = "notifiers"
15
15
 
16
- s.add_development_dependency('rspec', "~> 2.11")
16
+ s.add_development_dependency('rspec', "~> 2.14")
17
17
  s.add_development_dependency('bundler', ">= 1.0.0")
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module Notifiers
4
+ describe Base do
5
+ subject(:base) do
6
+ Base.new
7
+ end
8
+
9
+ describe '.subclasses' do
10
+ it { expect(Base.subclasses).to include(Growl, Knotify, NotifySend) }
11
+ end
12
+
13
+ describe '.installed?' do
14
+ it 'returns false as default' do
15
+ expect(Base).to_not be_installed
16
+ end
17
+ end
18
+
19
+ describe '.darwin?' do
20
+ context 'when the ruby platform is darwin' do
21
+ it 'returns true' do
22
+ expect(Base).to receive(:platform?).with(/darwin/).and_return(true)
23
+ expect(Base.darwin?).to be true
24
+ end
25
+ end
26
+
27
+ context 'when the ruby platform is not darwin' do
28
+ it 'returns false' do
29
+ expect(Base).to receive(:platform?).with(/darwin/).and_return(false)
30
+ expect(Base.darwin?).to be false
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#notify' do
36
+ before do
37
+ expect(base).to receive(:to_s).and_return('example')
38
+ end
39
+
40
+ context 'when the notify command runs without error' do
41
+ it 'calls system on #to_s method' do
42
+ expect(base).to receive(:system).with('example').and_return(true)
43
+ expect(base.notify).to be true
44
+ end
45
+ end
46
+
47
+ context 'when the notify command runs with error' do
48
+ it 'puts a install instruction if the system command returns false' do
49
+ expect(base).to receive(:system).with('example').and_return(false)
50
+ expect(base).to receive(:install_instructions).at_least(:once).and_return('Install')
51
+ expect(base).to receive(:puts).with('Install')
52
+ expect(base.notify).to be false
53
+ end
54
+
55
+ it 'do nothing when the instance does not have install instructions' do
56
+ expect(base).to receive(:system).with('example').and_return(false)
57
+ expect(base).to receive(:install_instructions).exactly(:once).and_return('')
58
+ expect(base).to_not receive(:puts)
59
+ expect(base.notify).to be false
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,108 +1,113 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Growl do
4
- before do
5
- @growl = growl
6
- end
7
-
8
- describe '#image' do
9
- it "should keep the image" do
10
- @growl.image('my_image.png')
11
- @growl.instance_variable_get(:@image).should eql 'my_image.png'
12
- end
3
+ module Notifiers
4
+ describe Growl do
5
+ it_should_behave_like 'a notifier'
13
6
 
14
- it "should set the image" do
15
- @growl.image('wario.png')
16
- @growl.instance_variable_get(:@image).should eql 'wario.png'
7
+ before do
8
+ @growl = growl
17
9
  end
18
10
 
19
- end
20
-
21
- describe '#message' do
11
+ describe '#image' do
12
+ it "should keep the image" do
13
+ @growl.image('my_image.png')
14
+ expect(@growl.instance_variable_get(:@image)).to eql 'my_image.png'
15
+ end
22
16
 
23
- it "should set the message option" do
24
- @growl.message('Hello World!')
25
- @growl.instance_variable_get(:@message).should eql 'Hello World!'
17
+ it "should set the image" do
18
+ @growl.image('wario.png')
19
+ expect(@growl.instance_variable_get(:@image)).to eql 'wario.png'
20
+ end
26
21
  end
27
22
 
28
- it "should set the message" do
29
- @growl.message('May the Force be with you')
30
- @growl.instance_variable_get(:@message).should eql 'May the Force be with you'
31
- end
32
- end
23
+ describe '#message' do
24
+ it "should set the message option" do
25
+ @growl.message('Hello World!')
26
+ expect(@growl.instance_variable_get(:@message)).to eql 'Hello World!'
27
+ end
33
28
 
34
- describe '#title' do
35
- it "should set the title" do
36
- @growl.title('Nirvana')
37
- @growl.instance_variable_get(:@title).should eql 'Nirvana'
29
+ it "should set the message" do
30
+ @growl.message('May the Force be with you')
31
+ expect(@growl.instance_variable_get(:@message)).to eql 'May the Force be with you'
32
+ end
38
33
  end
39
34
 
40
- it "should set the title option" do
41
- @growl.title('Pearl Jam')
42
- @growl.instance_variable_get(:@title).should eql 'Pearl Jam'
43
- end
44
- end
45
-
46
- describe '#priority' do
35
+ describe '#title' do
36
+ it "should set the title" do
37
+ @growl.title('Nirvana')
38
+ expect(@growl.instance_variable_get(:@title)).to eql 'Nirvana'
39
+ end
47
40
 
48
- it "should set the priority" do
49
- @growl.priority(0)
50
- @growl.instance_variable_get(:@priority).should be 0
41
+ it "should set the title option" do
42
+ @growl.title('Pearl Jam')
43
+ expect(@growl.instance_variable_get(:@title)).to eql 'Pearl Jam'
44
+ end
51
45
  end
52
46
 
53
- it "should set the priority number" do
54
- @growl.priority(1)
55
- @growl.instance_variable_get(:@priority).should be 1
56
- end
57
- end
58
-
59
- describe '#host' do
47
+ describe '#priority' do
48
+ it "should set the priority" do
49
+ @growl.priority(0)
50
+ expect(@growl.instance_variable_get(:@priority)).to be 0
51
+ end
60
52
 
61
- it "should set the hostname" do
62
- @growl.host('localhost')
63
- @growl.instance_variable_get(:@host).should eql 'localhost'
53
+ it "should set the priority number" do
54
+ @growl.priority(1)
55
+ expect(@growl.instance_variable_get(:@priority)).to be 1
56
+ end
64
57
  end
65
58
 
66
- it "should set the host" do
67
- @growl.host('beer_duff.com')
68
- @growl.instance_variable_get(:@host).should eql 'beer_duff.com'
59
+ describe '#host' do
60
+ it "should set the hostname" do
61
+ @growl.host('localhost')
62
+ expect(@growl.instance_variable_get(:@host)).to eql 'localhost'
63
+ end
64
+
65
+ it "should set the host" do
66
+ @growl.host('beer_duff.com')
67
+ expect(@growl.instance_variable_get(:@host)).to eql 'beer_duff.com'
68
+ end
69
69
  end
70
- end
71
70
 
72
- describe '#password' do
71
+ describe '#password' do
72
+ it "should set the password" do
73
+ @growl.password('top_secret')
74
+ expect(@growl.instance_variable_get(:@password)).to eql 'top_secret'
75
+ end
73
76
 
74
- it "should set the password" do
75
- @growl.password('top_secret')
76
- @growl.instance_variable_get(:@password).should eql 'top_secret'
77
+ it "should set the secret password" do
78
+ @growl.password('paradise_city')
79
+ expect(@growl.instance_variable_get(:@password)).to eql 'paradise_city'
80
+ end
77
81
  end
78
82
 
79
- it "should set the secret password" do
80
- @growl.password('paradise_city')
81
- @growl.instance_variable_get(:@password).should eql 'paradise_city'
83
+ describe '#auth' do
84
+ it "should set the auth option" do
85
+ @growl.auth('SHA256')
86
+ expect(@growl.instance_variable_get(:@auth)).to eql 'SHA256'
87
+ end
82
88
  end
83
- end
84
89
 
85
- describe '#auth' do
86
- it "should set the auth option" do
87
- @growl.auth('SHA256')
88
- @growl.instance_variable_get(:@auth).should eql 'SHA256'
89
- end
90
- end
90
+ describe '#to_s' do
91
+ it "should construct the command" do
92
+ command = @growl.message('Hello World!').priority(1).image('mario.png').to_s
93
+ expect(command).to eql "growlnotify --message 'Hello World!' --image mario.png --priority 1"
94
+ end
91
95
 
92
- describe '#to_s' do
93
- it "should construct the command" do
94
- command = @growl.message('Hello World!').priority(1).image('mario.png').to_s
95
- command.should eql "growlnotify --message 'Hello World!' --image mario.png --priority 1"
96
- end
96
+ it "should construct the command with host password and auth" do
97
+ command = @growl.message('Donuts').host('duff_bear').auth('SHA256').password('welcome_to_the_jungle').to_s
98
+ expect(command).to eql "growlnotify --message 'Donuts' --host duff_bear --password welcome_to_the_jungle --auth SHA256"
99
+ end
97
100
 
98
- it "should construct the command with host password and auth" do
99
- command = @growl.message('Donuts').host('duff_bear').auth('SHA256').password('welcome_to_the_jungle').to_s
100
- command.should eql "growlnotify --message 'Donuts' --host duff_bear --password welcome_to_the_jungle --auth SHA256"
101
+ it "should construct the command with title and message" do
102
+ command = @growl.message('Last Kiss').title('Pearl Jam').to_s
103
+ expect(command).to eql "growlnotify --title 'Pearl Jam' --message 'Last Kiss'"
104
+ end
101
105
  end
102
106
 
103
- it "should construct the command with title and message" do
104
- command = @growl.message('Last Kiss').title('Pearl Jam').to_s
105
- command.should eql "growlnotify --title 'Pearl Jam' --message 'Last Kiss'"
107
+ describe '#install_instructions' do
108
+ it 'returns an more concise message' do
109
+ expect(@growl.install_instructions).to eq 'The Growl is not installed. You can find more details here: http://growl.info/downloads'
110
+ end
106
111
  end
107
112
  end
108
113
  end
@@ -1,44 +1,42 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Knotify do
3
+ module Notifiers
4
+ describe Knotify do
5
+ it_should_behave_like 'a notifier'
4
6
 
5
- before do
6
- @knotify = Knotify.new
7
- end
8
-
9
- describe '#message' do
10
- it "should set the message instance variable" do
11
- @knotify.message('Bulls on Parade')
12
- @knotify.instance_variable_get(:@message).should == 'Bulls on Parade'
13
- end
14
-
15
- it "should be possible to set the message instance variable" do
16
- @knotify.message('Wake Up')
17
- @knotify.instance_variable_get(:@message).should == 'Wake Up'
7
+ before do
8
+ @knotify = Knotify.new
18
9
  end
19
- end
20
10
 
21
- describe '#title' do
11
+ describe '#message' do
12
+ it "should set the message instance variable" do
13
+ @knotify.message('Bulls on Parade')
14
+ expect(@knotify.instance_variable_get(:@message)).to eql 'Bulls on Parade'
15
+ end
22
16
 
23
- it "should set the title" do
24
- @knotify.title('Rage Against the Machine')
25
- @knotify.instance_variable_get(:@title).should == 'Rage Against the Machine'
17
+ it "should be possible to set the message instance variable" do
18
+ @knotify.message('Wake Up')
19
+ expect(@knotify.instance_variable_get(:@message)).to eql 'Wake Up'
20
+ end
26
21
  end
27
22
 
28
- it "should be possible to set the title" do
29
- @knotify.title('AudioSlave')
30
- @knotify.instance_variable_get(:@title).should == 'AudioSlave'
31
- end
23
+ describe '#title' do
24
+ it "should set the title" do
25
+ @knotify.title('Rage Against the Machine')
26
+ expect(@knotify.instance_variable_get(:@title)).to eql 'Rage Against the Machine'
27
+ end
32
28
 
33
- end
34
-
35
- describe '#to_s' do
36
-
37
- it "should return the entire command" do
38
- command = @knotify.title('Ruby').message('For the Win').to_s
39
- command.should == "dcop knotify default notify eventname 'Ruby' 'For the Win' '' '' 12 1"
29
+ it "should be possible to set the title" do
30
+ @knotify.title('AudioSlave')
31
+ expect(@knotify.instance_variable_get(:@title)).to eql 'AudioSlave'
32
+ end
40
33
  end
41
34
 
35
+ describe '#to_s' do
36
+ it "should return the entire command" do
37
+ command = @knotify.title('Ruby').message('For the Win').to_s
38
+ expect(command).to eql "dcop knotify default notify eventname 'Ruby' 'For the Win' '' '' 12 1"
39
+ end
40
+ end
42
41
  end
43
-
44
42
  end
@@ -1,117 +1,105 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe NotifySend do
3
+ module Notifiers
4
+ describe NotifySend do
5
+ it_should_behave_like 'a notifier'
4
6
 
5
- before do
6
- @notify_send = notify_send
7
- end
8
-
9
- describe '#image' do
10
-
11
- it "should set the image" do
12
- @notify_send.image('my_image.png')
13
- @notify_send.instance_variable_get(:@icon).should eql 'my_image.png'
14
- end
15
-
16
- it "should set the icon option" do
17
- @notify_send.image('homer_simpson.png')
18
- @notify_send.instance_variable_get(:@icon).should eql 'homer_simpson.png'
19
- end
20
-
21
- end
22
-
23
- describe '#message' do
24
-
25
- it "should set the message" do
26
- @notify_send.message('Oh Donuts!')
27
- @notify_send.instance_variable_get(:@message).should eql 'Oh Donuts!'
28
- end
29
-
30
- it "should set the message option" do
31
- @notify_send.message('Duff Beer')
32
- @notify_send.instance_variable_get(:@message).should eql 'Duff Beer'
7
+ before do
8
+ @notify_send = notify_send
33
9
  end
34
10
 
35
- end
36
-
37
- describe '#title' do
38
-
39
- it "should set the title" do
40
- @notify_send.title('W00T!!')
41
- @notify_send.instance_variable_get(:@title).should == 'W00T!!'
42
- end
11
+ describe '#image' do
12
+ it "should set the image" do
13
+ @notify_send.image('my_image.png')
14
+ expect(@notify_send.instance_variable_get(:@icon)).to eql 'my_image.png'
15
+ end
43
16
 
44
- it "should set a title as intance variable" do
45
- @notify_send.title('Joker Owned Batman!')
46
- @notify_send.instance_variable_get(:@title).should == 'Joker Owned Batman!'
17
+ it "should set the icon option" do
18
+ @notify_send.image('homer_simpson.png')
19
+ expect(@notify_send.instance_variable_get(:@icon)).to eql 'homer_simpson.png'
20
+ end
47
21
  end
48
22
 
49
- end
50
-
51
- describe '#urgency' do
23
+ describe '#message' do
24
+ it "should set the message" do
25
+ @notify_send.message('Oh Donuts!')
26
+ expect(@notify_send.instance_variable_get(:@message)).to eql 'Oh Donuts!'
27
+ end
52
28
 
53
- it "should set the urgency instance variable to low" do
54
- @notify_send.urgency(:low)
55
- @notify_send.instance_variable_get(:@urgency).should == 'low'
29
+ it "should set the message option" do
30
+ @notify_send.message('Duff Beer')
31
+ expect(@notify_send.instance_variable_get(:@message)).to eql 'Duff Beer'
32
+ end
56
33
  end
57
34
 
58
- it "should set he urgency instance variable to normal" do
59
- @notify_send.urgency(:normal)
60
- @notify_send.instance_variable_get(:@urgency).should == 'normal'
61
- end
35
+ describe '#title' do
36
+ it "should set the title" do
37
+ @notify_send.title('W00T!!')
38
+ expect(@notify_send.instance_variable_get(:@title)).to eql 'W00T!!'
39
+ end
62
40
 
63
- it "should set the urgency to critical" do
64
- @notify_send.urgency(:critical)
65
- @notify_send.instance_variable_get(:@urgency).should == 'critical'
41
+ it "should set a title as intance variable" do
42
+ @notify_send.title('Joker Owned Batman!')
43
+ expect(@notify_send.instance_variable_get(:@title)).to eql 'Joker Owned Batman!'
44
+ end
66
45
  end
67
46
 
68
- end
69
-
70
- describe '#expire_time' do
47
+ describe '#urgency' do
48
+ it "should set the urgency instance variable to low" do
49
+ @notify_send.urgency(:low)
50
+ expect(@notify_send.instance_variable_get(:@urgency)).to eql 'low'
51
+ end
71
52
 
72
- it "should set the expire time" do
73
- @notify_send.expire_time(1000)
74
- @notify_send.instance_variable_get(:@expire_time).should == 1000
75
- end
53
+ it "should set he urgency instance variable to normal" do
54
+ @notify_send.urgency(:normal)
55
+ expect(@notify_send.instance_variable_get(:@urgency)).to eql 'normal'
56
+ end
76
57
 
77
- it "should set the expire time in miliseconds" do
78
- @notify_send.expire_time(2000)
79
- @notify_send.instance_variable_get(:@expire_time).should == 2000
58
+ it "should set the urgency to critical" do
59
+ @notify_send.urgency(:critical)
60
+ expect(@notify_send.instance_variable_get(:@urgency)).to eql 'critical'
61
+ end
80
62
  end
81
63
 
82
- end
83
-
84
- describe '#hint' do
64
+ describe '#expire_time' do
65
+ it "should set the expire time" do
66
+ @notify_send.expire_time(1000)
67
+ expect(@notify_send.instance_variable_get(:@expire_time)).to eql 1000
68
+ end
85
69
 
86
- it "should set the hint" do
87
- @notify_send.hint([:string, :me, :yeah])
88
- @notify_send.instance_variable_get(:@hint).should == 'string:me:yeah'
70
+ it "should set the expire time in miliseconds" do
71
+ @notify_send.expire_time(2000)
72
+ expect(@notify_send.instance_variable_get(:@expire_time)).to eql 2000
73
+ end
89
74
  end
90
75
 
91
- it "should set the hint in int" do
92
- @notify_send.hint([:int, :me, 1])
93
- @notify_send.instance_variable_get(:@hint).should == 'int:me:1'
94
- end
95
-
96
- end
97
-
98
- describe '#to_s' do
76
+ describe '#hint' do
77
+ it "should set the hint" do
78
+ @notify_send.hint([:string, :me, :yeah])
79
+ expect(@notify_send.instance_variable_get(:@hint)).to eql 'string:me:yeah'
80
+ end
99
81
 
100
- it "should transform in a command" do
101
- command = @notify_send.title('Inception').message('3 levels').image('my_image.png').to_s
102
- command.should == "notify-send --icon=my_image.png 'Inception' '3 levels'"
82
+ it "should set the hint in int" do
83
+ @notify_send.hint([:int, :me, 1])
84
+ expect(@notify_send.instance_variable_get(:@hint)).to eql 'int:me:1'
85
+ end
103
86
  end
104
87
 
105
- it "should transform in a command to execute" do
106
- command = @notify_send.title('Joker').message('Haha ha!').expire_time(1000).hint([:string, :me, :woot]).to_s
107
- command.should == "notify-send --hint=string:me:woot --expire-time=1000 'Joker' 'Haha ha!'"
108
- end
88
+ describe '#to_s' do
89
+ it "should transform in a command" do
90
+ command = @notify_send.title('Inception').message('3 levels').image('my_image.png').to_s
91
+ expect(command).to eql "notify-send --icon=my_image.png 'Inception' '3 levels'"
92
+ end
109
93
 
110
- it "should transform in a command to execute" do
111
- command = @notify_send.title('Batman').urgency(:critical).to_s
112
- command.should == "notify-send --urgency=critical 'Batman'"
113
- end
94
+ it "should transform in a command to execute" do
95
+ 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!'"
97
+ end
114
98
 
99
+ it "should transform in a command to execute" do
100
+ command = @notify_send.title('Batman').urgency(:critical).to_s
101
+ expect(command).to eql "notify-send --urgency=critical 'Batman'"
102
+ end
103
+ end
115
104
  end
116
-
117
105
  end
@@ -1,13 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'notifiers' do
3
+ describe Notifiers do
4
+ it { expect(growl).to be_instance_of(Notifiers::Growl) }
4
5
 
5
- it { growl.should be_instance_of(Growl) }
6
+ it { expect(knotify).to be_instance_of(Notifiers::Knotify) }
6
7
 
7
- it { knotify.should be_instance_of(Knotify) }
8
+ it { expect(notify_send).to be_instance_of(Notifiers::NotifySend) }
8
9
 
9
- it { notify_send.should be_instance_of(NotifySend)}
10
+ it { expect(lib_notify).to be_instance_of(Notifiers::NotifySend) }
10
11
 
11
- it { lib_notify.should be_instance_of(NotifySend)}
12
+ describe '#auto_discover' do
13
+ context 'when have a notifier library installed' do
14
+ 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)
17
+ end
18
+ end
12
19
 
20
+ context 'when do not have a notifier library installed' do
21
+ it 'raises Notifier not Found' do
22
+ expect(Notifiers::Base).to receive(:subclasses).and_return([])
23
+ expect {
24
+ auto_discover
25
+ }.to raise_error(Notifiers::NotifierNotFound)
26
+ end
27
+ end
28
+ end
13
29
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,22 @@
1
-
1
+ require 'bundler/setup'
2
2
  require 'notifiers'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.include Notifiers
6
+ config.filter_run focus: true
7
+ config.run_all_when_everything_filtered = true
8
+
9
+ config.expect_with :rspec do |c|
10
+ c.syntax = :expect
11
+ end
12
+ end
13
+
14
+ shared_examples_for 'a notifier' do
15
+ describe '#notify' do
16
+ it { expect(subject).to respond_to(:notify) }
17
+ end
18
+
19
+ describe '.installed?' do
20
+ it { expect(described_class).to respond_to(:installed?) }
21
+ end
6
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifiers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás D'Stefano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '2.11'
19
+ version: '2.14'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '2.11'
26
+ version: '2.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -48,17 +48,20 @@ files:
48
48
  - .gitignore
49
49
  - .infinity_test
50
50
  - .rspec
51
+ - .travis.yml
51
52
  - Gemfile
52
- - Gemfile.lock
53
53
  - History.markdown
54
54
  - README.markdown
55
55
  - Rakefile
56
56
  - TODO.markdown
57
57
  - lib/notifiers.rb
58
+ - lib/notifiers/base.rb
58
59
  - lib/notifiers/growl.rb
59
60
  - lib/notifiers/knotify.rb
61
+ - lib/notifiers/notifier_not_found.rb
60
62
  - lib/notifiers/notify_send.rb
61
63
  - notifiers.gemspec
64
+ - spec/notifiers/base_spec.rb
62
65
  - spec/notifiers/growl_spec.rb
63
66
  - spec/notifiers/knotify_spec.rb
64
67
  - spec/notifiers/notify_send_spec.rb
data/Gemfile.lock DELETED
@@ -1,25 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- notifiers (1.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- diff-lcs (1.1.3)
10
- rspec (2.11.0)
11
- rspec-core (~> 2.11.0)
12
- rspec-expectations (~> 2.11.0)
13
- rspec-mocks (~> 2.11.0)
14
- rspec-core (2.11.1)
15
- rspec-expectations (2.11.3)
16
- diff-lcs (~> 1.1.3)
17
- rspec-mocks (2.11.3)
18
-
19
- PLATFORMS
20
- ruby
21
-
22
- DEPENDENCIES
23
- bundler (>= 1.0.0)
24
- notifiers!
25
- rspec (~> 2.11)