Merge pull request #51 from indirect/guard

---

This change allows guard plugins (like guard-rspec) to pass options (like :priority) up to the Growl notifier. With this change, things like indirect/rspec-guard@d2f01d69a7 are possible, and the growl notification colors can be customized depending on the outcome of the spec run.

Conflicts:
	lib/guard/notifier.rb
This commit is contained in:
Michael Kessler 2011-05-30 16:45:15 +02:00
commit 320706e2f5
3 changed files with 97 additions and 10 deletions

View File

@ -1,3 +1,9 @@
## Master
### New features:
- Pull request [#51](https://github.com/guard/guard/pull/51): Allow options (like :priority) to be passed through to the Notifier ([@indirect](https://github.com/indirect) and [@netzpirat](https://github.com/netzpirat))
## 0.4.0.rc - May 28, 2011
### Bugs fixes:
@ -111,4 +117,4 @@
### New features:
- Improved listeners support (`rb-fsevent` & `rb-inotify`). ([@thibaudgg](https://github.com/thibaudgg))
- Added polling listening fallback. ([@thibaudgg](https://github.com/thibaudgg))
- Added polling listening fallback. ([@thibaudgg](https://github.com/thibaudgg))

View File

@ -23,18 +23,16 @@ module Guard
def self.notify(message, options = {})
if enabled?
image = options[:image] || :success
title = options[:title] || "Guard"
image = options.delete(:image) || :success
title = options.delete(:title) || "Guard"
case Config::CONFIG['target_os']
when /darwin/i
require_growl # need for guard-rspec formatter that is called out of guard scope
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
notify_mac(title, message, image, options)
when /linux/i
require_libnotify # need for guard-rspec formatter that is called out of guard scope
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
notify_linux(title, message, image, options)
when /mswin|mingw/i
require_rbnotifu
Notifu.show :message => message, :title => title, :type => image_level(image), :time => 3
notify_windows(title, message, image, options)
end
end
end
@ -45,6 +43,24 @@ module Guard
private
def self.notify_mac(title, message, image, options)
require_growl # need for guard-rspec formatter that is called out of guard scope
default_options = { :title => title, :icon => image_path(image), :name => "Guard" }
Growl.notify message, default_options.merge(options)
end
def self.notify_linux(title, message, image, options)
require_libnotify # need for guard-rspec formatter that is called out of guard scope
default_options = { :body => message, :summary => title, :icon_path => image_path(image) }
Libnotify.show default_options.merge(options)
end
def self.notify_windows(title, message, image, options)
require_rbnotifu # need for guard-rspec formatter that is called out of guard scope
default_options = { :message => message, :title => title, :type => image_level(image), :time => 3 }
Notifu.show default_options.merge(options)
end
def self.image_path(image)
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
case image
@ -72,7 +88,7 @@ module Guard
:info
end
end
def self.require_growl
require 'growl'
rescue LoadError

View File

@ -63,6 +63,8 @@ describe Guard::Notifier do
Growl = Object.new
end
around { Object.send(:remove_const, :Growl) if defined?(Growl) }
it "passes the notification to Growl" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
@ -71,6 +73,25 @@ describe Guard::Notifier do
)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard",
:priority => 1
)
subject.notify 'great', :title => 'Guard', :priority => 1
end
it "allows to overwrite a default notification option" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard-Cucumber"
)
subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
end
end
context "on Linux" do
@ -80,6 +101,8 @@ describe Guard::Notifier do
Libnotify = Object.new
end
around { Object.send(:remove_const, :Libnotify) if defined?(Libnotify) }
it "passes the notification to Libnotify" do
Libnotify.should_receive(:show).with(
:body => "great",
@ -88,6 +111,25 @@ describe Guard::Notifier do
)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Libnotify.should_receive(:show).with(
:body => "great",
:summary => 'Guard',
:icon_path => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:urgency => :critical
)
subject.notify 'great', :title => 'Guard', :urgency => :critical
end
it "allows to overwrite a default notification option" do
Libnotify.should_receive(:show).with(
:body => "great",
:summary => 'Guard',
:icon_path => '~/.guard/success.png'
)
subject.notify 'great', :title => 'Guard', :icon_path => '~/.guard/success.png'
end
end
context "on Windows" do
@ -97,6 +139,8 @@ describe Guard::Notifier do
Notifu = Object.new
end
around { Object.send(:remove_const, :Notifu) if defined?(Notify) }
it "passes the notification to rb-notifu" do
Notifu.should_receive(:show).with(
:message => "great",
@ -106,6 +150,27 @@ describe Guard::Notifier do
)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
Notifu.should_receive(:show).with(
:message => "great",
:title => 'Guard',
:type => :info,
:time => 3,
:nosound => true
)
subject.notify 'great', :title => 'Guard', :nosound => true
end
it "allows to overwrite a default notification option" do
Notifu.should_receive(:show).with(
:message => "great",
:title => 'Guard',
:type => :info,
:time => 10
)
subject.notify 'great', :title => 'Guard', :time => 10
end
end
end