force use of Guard application name when using growl_notify

This commit is contained in:
John Bintz 2011-07-01 11:52:24 -04:00
parent 8917682cdf
commit facd4f2a0b
2 changed files with 13 additions and 25 deletions

View File

@ -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

View File

@ -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