Merge pull request #99 from johnbintz/also-use-growl_notify
Option to also use growl_notify gem
This commit is contained in:
commit
3c326611e9
2
Gemfile
2
Gemfile
@ -12,7 +12,7 @@ require 'rbconfig'
|
|||||||
|
|
||||||
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
if RbConfig::CONFIG['target_os'] =~ /darwin/i
|
||||||
gem 'rb-fsevent', '>= 0.4.0', :require => false
|
gem 'rb-fsevent', '>= 0.4.0', :require => false
|
||||||
gem 'growl', '~> 1.0.3', :require => false
|
gem 'growl_notify', :require => false
|
||||||
end
|
end
|
||||||
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
if RbConfig::CONFIG['target_os'] =~ /linux/i
|
||||||
gem 'rb-inotify', '>= 0.8.5', :require => false
|
gem 'rb-inotify', '>= 0.8.5', :require => false
|
||||||
|
@ -50,17 +50,17 @@ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents)
|
|||||||
$ gem install rb-fsevent
|
$ gem install rb-fsevent
|
||||||
```
|
```
|
||||||
|
|
||||||
Install the Growl gem if you want notification support:
|
Install the growl_notify gem if you want notification support:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
$ gem install growl
|
$ gem install growl_notify
|
||||||
```
|
```
|
||||||
|
|
||||||
And add them to your Gemfile:
|
And add it to your Gemfile:
|
||||||
|
|
||||||
``` ruby
|
``` ruby
|
||||||
gem 'rb-fsevent'
|
gem 'rb-fsevent'
|
||||||
gem 'growl'
|
gem 'growl_notify'
|
||||||
```
|
```
|
||||||
|
|
||||||
### On Linux
|
### On Linux
|
||||||
|
@ -4,6 +4,7 @@ require 'guard/ui'
|
|||||||
|
|
||||||
module Guard
|
module Guard
|
||||||
module Notifier
|
module Notifier
|
||||||
|
APPLICATION_NAME = "Guard"
|
||||||
|
|
||||||
def self.turn_off
|
def self.turn_off
|
||||||
ENV["GUARD_NOTIFY"] = 'false'
|
ENV["GUARD_NOTIFY"] = 'false'
|
||||||
@ -45,8 +46,11 @@ module Guard
|
|||||||
|
|
||||||
def self.notify_mac(title, message, image, options)
|
def self.notify_mac(title, message, image, options)
|
||||||
require_growl # need for guard-rspec formatter that is called out of guard scope
|
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
|
end
|
||||||
|
|
||||||
def self.notify_linux(title, message, image, options)
|
def self.notify_linux(title, message, image, options)
|
||||||
@ -90,10 +94,17 @@ module Guard
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.require_growl
|
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
|
rescue LoadError
|
||||||
turn_off
|
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
|
end
|
||||||
|
|
||||||
def self.require_libnotify
|
def self.require_libnotify
|
||||||
|
@ -20,17 +20,28 @@ describe Guard::Notifier do
|
|||||||
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
|
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
|
||||||
end
|
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
|
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.turn_on
|
||||||
subject.should be_enabled
|
subject.should be_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
Object.send(:remove_const, :GrowlNotify)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "without the Growl library available" do
|
context "without the GrowlNofity library available" do
|
||||||
it "disables the notifications" 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.turn_on
|
||||||
subject.should_not be_enabled
|
subject.should_not be_enabled
|
||||||
end
|
end
|
||||||
@ -89,46 +100,54 @@ describe Guard::Notifier do
|
|||||||
before do
|
before do
|
||||||
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
|
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
|
||||||
subject.stub(:require_growl)
|
subject.stub(:require_growl)
|
||||||
Object.send(:remove_const, :Growl) if defined?(Growl)
|
|
||||||
Growl = Object.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
context 'with growl_notify gem' do
|
||||||
Object.send(:remove_const, :Growl)
|
before do
|
||||||
end
|
Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
|
||||||
|
GrowlNotify = Object.new
|
||||||
|
end
|
||||||
|
|
||||||
it "passes the notification to Growl" do
|
after do
|
||||||
Growl.should_receive(:notify).with("great",
|
Object.send(:remove_const, :GrowlNotify)
|
||||||
:title => "Guard",
|
end
|
||||||
: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
|
it "passes the notification to Growl" do
|
||||||
Growl.should_not_receive(:notify)
|
GrowlNotify.should_receive(:send_notification).with(
|
||||||
subject.should_receive(:enabled?).and_return(true, false)
|
:title => "Guard",
|
||||||
subject.notify 'great', :title => 'Guard'
|
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
||||||
end
|
:application_name => "Guard",
|
||||||
|
:description => 'great'
|
||||||
|
)
|
||||||
|
subject.notify 'great', :title => 'Guard'
|
||||||
|
end
|
||||||
|
|
||||||
it "allows additional notification options" do
|
it "don't passes the notification to Growl if library is not available" do
|
||||||
Growl.should_receive(:notify).with("great",
|
GrowlNotify.should_not_receive(:send_notification)
|
||||||
:title => "Guard",
|
subject.should_receive(:enabled?).and_return(true, false)
|
||||||
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
subject.notify 'great', :title => 'Guard'
|
||||||
:name => "Guard",
|
end
|
||||||
:priority => 1
|
|
||||||
)
|
|
||||||
subject.notify 'great', :title => 'Guard', :priority => 1
|
|
||||||
end
|
|
||||||
|
|
||||||
it "allows to overwrite a default notification option" do
|
it "allows additional notification options" do
|
||||||
Growl.should_receive(:notify).with("great",
|
GrowlNotify.should_receive(:send_notification).with(
|
||||||
:title => "Guard",
|
:title => "Guard",
|
||||||
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
:icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
|
||||||
:name => "Guard-Cucumber"
|
:application_name => "Guard",
|
||||||
)
|
:description => 'great',
|
||||||
subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
|
: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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user