From d41e9fe7feaff993e412a56035bc49320b3894ee Mon Sep 17 00:00:00 2001 From: Yann Lugrin Date: Tue, 7 Jun 2011 17:58:02 +0200 Subject: [PATCH] don't use system notification library if could not be required --- lib/guard/notifier.rb | 6 +++--- spec/guard/notifier_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index f0258b8..ec7e54d 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -46,19 +46,19 @@ module Guard 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) + Growl.notify message, default_options.merge(options) if enabled? 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) + Libnotify.show default_options.merge(options) if enabled? 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) + Notifu.show default_options.merge(options) if enabled? end def self.image_path(image) diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index bf69204..bb4ef18 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -107,6 +107,12 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard' 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 Growl.should_receive(:notify).with("great", :title => "Guard", @@ -148,6 +154,12 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard' 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 Libnotify.should_receive(:show).with( :body => "great", @@ -190,6 +202,12 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard' 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 Notifu.should_receive(:show).with( :message => "great",