add support for growl_notify

This commit is contained in:
John Bintz 2011-06-28 16:15:14 -04:00
parent 59b1ea2c96
commit e53036ad05
2 changed files with 128 additions and 36 deletions

View File

@ -45,8 +45,18 @@ 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) if enabled?
default_options.merge!(options)
if defined?(GrowlNotify)
default_options[:description] = message
default_options[:application_name] = default_options.delete(:name)
GrowlNotify.send_notification(default_options) if enabled?
else
Growl.notify message, default_options.merge(options) if enabled?
end
end
def self.notify_linux(title, message, image, options)
@ -90,10 +100,19 @@ module Guard
end
def self.require_growl
require 'growl'
begin
require 'growl_notify'
GrowlNotify.config do |c|
c.notifications = c.default_notifications = [ "Guard" ]
c.application_name = c.notifications.first
end
rescue LoadError
require 'growl'
end
rescue LoadError
turn_off
UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
UI.info "Please install growl or growl_notify gem for Mac OS X notification support and add it to your Gemfile"
end
def self.require_libnotify

View File

@ -20,8 +20,27 @@ describe Guard::Notifier do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
end
context "with the GrowlNotify library available" do
before do
module ::GrowlNotify
def self.config ; end
end
end
it "loads the library and enables the notifications" do
subject.should_receive(:require).with('growl_notify').and_return true
subject.turn_on
subject.should be_enabled
end
after do
Object.send(:remove_const, :GrowlNotify)
end
end
context "with the Growl library available" do
it "loads the library and enables the notifications" do
subject.should_receive(:require).with('growl_notify').and_raise LoadError
subject.should_receive(:require).with('growl').and_return true
subject.turn_on
subject.should be_enabled
@ -30,6 +49,7 @@ describe Guard::Notifier do
context "without the Growl library available" do
it "disables the notifications" do
subject.should_receive(:require).with('growl_notify').and_raise LoadError
subject.should_receive(:require).with('growl').and_raise LoadError
subject.turn_on
subject.should_not be_enabled
@ -89,46 +109,99 @@ describe Guard::Notifier do
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
subject.stub(:require_growl)
Object.send(:remove_const, :Growl) if defined?(Growl)
Growl = Object.new
end
after do
Object.send(:remove_const, :Growl)
context 'with growl gem' do
before do
Object.send(:remove_const, :Growl) if defined?(Growl)
Growl = Object.new
end
after do
Object.send(:remove_const, :Growl)
end
it "passes the notification to Growl" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard"
)
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",
: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
it "passes the notification to Growl" do
Growl.should_receive(:notify).with("great",
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:name => "Guard"
)
subject.notify 'great', :title => 'Guard'
end
context 'with growl_notify gem' do
before do
Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
GrowlNotify = Object.new
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
after do
Object.send(:remove_const, :GrowlNotify)
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 "passes the notification to Growl" do
GrowlNotify.should_receive(:send_notification).with(
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:application_name => "Guard",
:description => 'great'
)
subject.notify 'great', :title => 'Guard'
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"
it "don't passes the notification to Growl if library is not available" do
GrowlNotify.should_not_receive(:send_notification)
subject.should_receive(:enabled?).and_return(true, false)
subject.notify 'great', :title => 'Guard'
end
it "allows additional notification options" do
GrowlNotify.should_receive(:send_notification).with(
:title => "Guard",
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
:application_name => "Guard",
:description => 'great',
:priority => 1
)
subject.notify 'great', :title => 'Guard', :priority => 1
end
it "allows to overwrite a default notification option" 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",
:description => 'great'
)
subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
end
end
end