don't use system notification library if could not be required

This commit is contained in:
Yann Lugrin 2011-06-07 17:58:02 +02:00
parent e2b13d2dc5
commit d41e9fe7fe
2 changed files with 21 additions and 3 deletions

View File

@ -46,19 +46,19 @@ module Guard
def self.notify_mac(title, message, image, options) def self.notify_mac(title, message, image, options)
require_growl # need for guard-rspec formatter that is called out of guard scope require_growl # need for guard-rspec formatter that is called out of guard scope
default_options = { :title => title, :icon => image_path(image), :name => "Guard" } default_options = { :title => title, :icon => image_path(image), :name => "Guard" }
Growl.notify message, default_options.merge(options) Growl.notify message, default_options.merge(options) if enabled?
end end
def self.notify_linux(title, message, image, options) def self.notify_linux(title, message, image, options)
require_libnotify # need for guard-rspec formatter that is called out of guard scope 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) } default_options = { :body => message, :summary => title, :icon_path => image_path(image) }
Libnotify.show default_options.merge(options) Libnotify.show default_options.merge(options) if enabled?
end end
def self.notify_windows(title, message, image, options) def self.notify_windows(title, message, image, options)
require_rbnotifu # need for guard-rspec formatter that is called out of guard scope 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 } default_options = { :message => message, :title => title, :type => image_level(image), :time => 3 }
Notifu.show default_options.merge(options) Notifu.show default_options.merge(options) if enabled?
end end
def self.image_path(image) def self.image_path(image)

View File

@ -107,6 +107,12 @@ describe Guard::Notifier do
subject.notify 'great', :title => 'Guard' subject.notify 'great', :title => 'Guard'
end end
it "don't passes the notification to Growl if library is not available" do
Growl.should_not_receive(:notify)
subject.should_receive(:enabled?).and_return(true, false)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do it "allows additional notification options" do
Growl.should_receive(:notify).with("great", Growl.should_receive(:notify).with("great",
:title => "Guard", :title => "Guard",
@ -148,6 +154,12 @@ describe Guard::Notifier do
subject.notify 'great', :title => 'Guard' subject.notify 'great', :title => 'Guard'
end end
it "don't passes the notification to Libnotify if library is not available" do
Libnotify.should_not_receive(:show)
subject.should_receive(:enabled?).and_return(true, false)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do it "allows additional notification options" do
Libnotify.should_receive(:show).with( Libnotify.should_receive(:show).with(
:body => "great", :body => "great",
@ -190,6 +202,12 @@ describe Guard::Notifier do
subject.notify 'great', :title => 'Guard' subject.notify 'great', :title => 'Guard'
end end
it "don't passes the notification to rb-notifu if library is not available" do
Notifu.should_not_receive(:show)
subject.should_receive(:enabled?).and_return(true, false)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do it "allows additional notification options" do
Notifu.should_receive(:show).with( Notifu.should_receive(:show).with(
:message => "great", :message => "great",