Merge pull request #99 from johnbintz/also-use-growl_notify

Option to also use growl_notify gem
This commit is contained in:
Thibaud Guillaume-Gentil 2011-08-13 07:42:08 -07:00
commit 3c326611e9
4 changed files with 77 additions and 47 deletions

View File

@ -12,7 +12,7 @@ require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.4.0', :require => false
gem 'growl', '~> 1.0.3', :require => false
gem 'growl_notify', :require => false
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.8.5', :require => false

View File

@ -50,17 +50,17 @@ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents)
$ gem install rb-fsevent
```
Install the Growl gem if you want notification support:
Install the growl_notify gem if you want notification support:
``` bash
$ gem install growl
$ gem install growl_notify
```
And add them to your Gemfile:
And add it to your Gemfile:
``` ruby
gem 'rb-fsevent'
gem 'growl'
gem 'growl_notify'
```
### On Linux

View File

@ -4,6 +4,7 @@ require 'guard/ui'
module Guard
module Notifier
APPLICATION_NAME = "Guard"
def self.turn_off
ENV["GUARD_NOTIFY"] = 'false'
@ -45,8 +46,11 @@ 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?
options = { :description => message, :title => title, :icon => image_path(image), :application_name => APPLICATION_NAME }.merge(options)
options.delete(:name)
GrowlNotify.send_notification(options) if enabled?
end
def self.notify_linux(title, message, image, options)
@ -90,10 +94,17 @@ module Guard
end
def self.require_growl
require 'growl'
require 'growl_notify'
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
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_notify gem for Mac OS X notification support and add it to your Gemfile"
end
def self.require_libnotify

View File

@ -20,17 +20,28 @@ describe Guard::Notifier do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
end
context "with the Growl library available" do
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').and_return true
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
after do
Object.send(:remove_const, :GrowlNotify)
end
end
context "without the Growl library available" do
context "without the GrowlNofity library available" do
it "disables the notifications" do
subject.should_receive(:require).with('growl').and_raise LoadError
subject.should_receive(:require).with('growl_notify').and_raise LoadError
subject.turn_on
subject.should_not be_enabled
end
@ -89,46 +100,54 @@ 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)
end
context 'with growl_notify gem' do
before do
Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
GrowlNotify = Object.new
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
after do
Object.send(:remove_const, :GrowlNotify)
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 "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 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 "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 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 "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 "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",
:description => 'great'
)
subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
end
end
end