From facd4f2a0b1e1a2b99fc8569f190903f690e24b3 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 1 Jul 2011 11:52:24 -0400 Subject: [PATCH] force use of Guard application name when using growl_notify --- lib/guard/notifier.rb | 21 ++++++++++----------- spec/guard/notifier_spec.rb | 17 +++-------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 695ce7c..19820fc 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -4,6 +4,7 @@ require 'guard/ui' module Guard module Notifier + APPLICATION_NAME = "Guard" def self.turn_off ENV["GUARD_NOTIFY"] = 'false' @@ -46,13 +47,13 @@ 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" } + default_options = { :title => title, :icon => image_path(image), :name => APPLICATION_NAME } default_options.merge!(options) if defined?(GrowlNotify) default_options[:description] = message - default_options[:application_name] = default_options.delete(:name) - growl_notify_config(default_options[:application_name]) if default_options[:application_name] != 'Guard' + default_options[:application_name] = APPLICATION_NAME + default_options.delete(:name) GrowlNotify.send_notification(default_options) if enabled? else @@ -104,7 +105,12 @@ module Guard begin require 'growl_notify' - growl_notify_config + if GrowlNotify.application_name != APPLICATION_NAME + GrowlNotify.config do |c| + c.notifications = c.default_notifications = [ APPLICATION_NAME ] + c.application_name = c.notifications.first + end + end rescue LoadError require 'growl' end @@ -126,12 +132,5 @@ module Guard turn_off UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile" end - - def self.growl_notify_config(additional_applications = []) - GrowlNotify.config do |c| - c.notifications = c.default_notifications = [ "Guard", additional_applications ].flatten - c.application_name = c.notifications.first - end - end end end diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 0d3b90b..5b376b5 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -29,6 +29,7 @@ describe Guard::Notifier do it "loads the library and enables the notifications" do subject.should_receive(:require).with('growl_notify').and_return true + GrowlNotify.should_receive(:application_name).and_return '' subject.turn_on subject.should be_enabled end @@ -193,26 +194,14 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard', :priority => 1 end - it "allows to overwrite a default notification option" do - config = Class.new do - attr_accessor :notifications, :default_notifications, :application_name - end.new - - apps = ["Guard", "Guard-Cucumber"] - - GrowlNotify.should_receive(:config).and_yield(config) - + it "throws out the application name since Guard should only use one Growl App Name while running" do GrowlNotify.should_receive(:send_notification).with( :title => "Guard", :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s, - :application_name => "Guard-Cucumber", + :application_name => "Guard", :description => 'great' ) subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber" - - config.notifications.should == apps - config.default_notifications.should == apps - config.application_name.should == apps.first end end end