Added a command line option (-n false) to disable notifications (growl/libnotify). closed #28

This commit is contained in:
Thibaud Guillaume-Gentil 2011-04-10 22:32:29 +02:00
parent 31c43f7c13
commit 42c27242e1
7 changed files with 87 additions and 54 deletions

View File

@ -17,6 +17,9 @@ module Guard
@options = options
@listener = Listener.select_and_init
@guards = []
Notifier.turn_off unless options[:notify]
self
end

View File

@ -6,6 +6,7 @@ module Guard
default_task :start
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell before each change/run_all/reload"
method_option :notify, :type => :boolean, :default => true, :aliases => '-n', :banner => "Notifications feature (growl/libnotify)"
method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages"
method_option :group, :type => :array, :default => [], :aliases => '-g', :banner => "Run only the passed groups"

View File

@ -4,8 +4,12 @@ require 'pathname'
module Guard
module Notifier
def self.turn_off
@disable = true
end
def self.notify(message, options = {})
unless ENV["GUARD_ENV"] == "test"
unless @disable || ENV["GUARD_ENV"] == "test"
image = options[:image] || :success
title = options[:title] || "Guard"
case Config::CONFIG['target_os']

View File

@ -30,6 +30,26 @@ describe Guard::Notifier do
end
end
context "turned off" do
before(:each) { subject.turn_off }
if mac?
require 'growl'
it "should do nothing" do
Growl.should_not_receive(:notify)
subject.notify 'great', :title => 'Guard'
end
end
if linux?
require 'libnotify'
it "should do nothing" do
Libnotify.should_not_receive(:show)
subject.notify 'great', :title => 'Guard'
end
end
end
after(:each) { ENV["GUARD_ENV"] = 'test' }
end

View File

@ -22,6 +22,11 @@ describe Guard do
it "should init listener" do
::Guard.listener.should be_kind_of(Guard::Listener)
end
it "should turn off notifier if notify option is false" do
::Guard::Notifier.should_receive(:turn_off)
::Guard.setup(:notify => false)
end
end
describe ".get_guard_class" do