Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Notifier calls .available? with options #408

Merged
merged 2 commits into from

3 participants

@amiel
Collaborator

This allows FileNotifier to not be available? when it is not configured with a :path.

There are also a few other places where .available? uses a DEFAULTS hash to check availability, but could not consult user options. This would theoretically be a bug if the user configured a notifier in such a way that it would only be considered available with their options.

@amiel
Collaborator

BTW,
There was one failing test before this pull-request. It is still failing.

  1) Guard::Dsl#callback creates callbacks for the guard
     Failure/Error: described_class.evaluate_guardfile(:guardfile_contents => '
       Guard received :add_guard with unexpected arguments
         expected: ("dummy", #<RSpec::Mocks::ArgumentMatchers::AnyArgMatcher:0x007f984135be30>, #<RSpec::Mocks::ArgumentMatchers::AnyArgMatcher:0x007f984135be08>, {:group=>:default})
              got: ("shell", [#<Guard::Watcher:0x007f98416bde70 @action=#<Proc:0x007f98416bde98@Inline Guardfile:11>, @pattern=".guard_result">], [], {:group=>:default})
     # ./lib/guard/dsl.rb:354:in `guard'
     # Inline Guardfile:10:in `instance_eval_guardfile'
     # ./lib/guard/dsl.rb:119:in `instance_eval'
     # ./lib/guard/dsl.rb:119:in `instance_eval_guardfile'
     # ./lib/guard/dsl.rb:74:in `evaluate_guardfile'
     # ./spec/guard/dsl_spec.rb:504:in `block (3 levels) in <top (required)>'
@coveralls

Changes Unknown when pulling abcb4e2 on amiel:available_options into ** on guard:master**.

View Details

@netzpirat netzpirat merged commit abcb4e2 into guard:master

1 check failed

Details default The Travis build failed
@netzpirat
Owner

We have now an open commit bit policy and you're the first contributor! Welcome @amiel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -15,6 +15,8 @@ Gemfile.lock
bin/fsevent_watch_guard
Makefile
+.guard_result
+
## MAC OS
.DS_Store
.Trashes
View
2  lib/guard/notifier.rb
@@ -155,7 +155,7 @@ def add_notification(name, options = { }, silent = false)
notifier = get_notifier_module(name)
- if notifier && notifier.available?(silent)
+ if notifier && notifier.available?(silent, options)
self.notifications = notifications << { :name => name, :options => options }
true
else
View
5 lib/guard/notifiers/emacs.rb
@@ -22,10 +22,11 @@ module Emacs
# Test if Emacs with running server is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
- result = `#{ DEFAULTS[:client] } --eval '1' 2> #{DEV_NULL} || echo 'N/A'`
+ def available?(silent = false, options = {})
+ result = `#{ options.fetch(:client, DEFAULTS[:client]) } --eval '1' 2> #{DEV_NULL} || echo 'N/A'`
if %w(N/A 'N/A').include?(result.chomp!)
false
View
7 lib/guard/notifiers/file_notifier.rb
@@ -20,10 +20,11 @@ module FileNotifier
# we don't get options in available?.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
- true
+ def available?(silent = false, options = {})
+ options.has_key?(:path)
end
# Write the notification to a file. By default it writes type, tytle, and
@@ -42,6 +43,8 @@ def notify(type, title, message, image, options = { })
format = options.fetch(:format, DEFAULTS[:format])
write(options[:path], format % [type, title, message])
+ else
+ ::Guard::UI.error ':file notifier requires a :path option'
end
end
View
3  lib/guard/notifiers/gntp.rb
@@ -54,9 +54,10 @@ def registered!
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if RbConfig::CONFIG['host_os'] =~ /darwin|linux|freebsd|openbsd|sunos|solaris|mswin|mingw|cygwin/
require 'ruby_gntp'
true
View
3  lib/guard/notifiers/growl.rb
@@ -43,9 +43,10 @@ module Growl
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if RbConfig::CONFIG['host_os'] =~ /darwin/
require 'growl'
View
3  lib/guard/notifiers/growl_notify.rb
@@ -32,9 +32,10 @@ module GrowlNotify
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if RbConfig::CONFIG['host_os'] =~ /darwin/
require 'growl_notify'
View
3  lib/guard/notifiers/libnotify.rb
@@ -33,9 +33,10 @@ module Libnotify
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/
require 'libnotify'
View
3  lib/guard/notifiers/notifysend.rb
@@ -25,9 +25,10 @@ module NotifySend
# Test if the notification program is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if (RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/) and (not `which notify-send`.empty?)
true
else
View
3  lib/guard/notifiers/rb_notifu.rb
@@ -36,9 +36,10 @@ module Notifu
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
require 'rb-notifu'
View
3  lib/guard/notifiers/terminal_notifier.rb
@@ -25,9 +25,10 @@ module TerminalNotifier
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent=false)
+ def available?(silent = false, options = {})
require 'terminal-notifier-guard'
if ::TerminalNotifier::Guard.available?
View
3  lib/guard/notifiers/terminal_title.rb
@@ -7,9 +7,10 @@ module TerminalTitle
# Test if the notification library is available.
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
+ def available?(silent = false, options = {})
true
end
View
5 lib/guard/notifiers/tmux.rb
@@ -35,10 +35,11 @@ module Tmux
# Test if currently running in a Tmux session
#
# @param [Boolean] silent true if no error messages should be shown
+ # @param [Hash] options notifier options
# @return [Boolean] the availability status
#
- def available?(silent = false)
- if ENV[DEFAULTS[:tmux_environment]].nil?
+ def available?(silent = false, options = {})
+ if ENV[options.fetch(:tmux_environment, DEFAULTS[:tmux_environment])].nil?
::Guard::UI.error 'The :tmux notifier runs only on when Guard is executed inside of a tmux session.' unless silent
false
else
View
9 spec/guard/notifiers/file_notifier_spec.rb
@@ -4,8 +4,12 @@
describe Guard::Notifier::FileNotifier do
describe '.available?' do
- it 'is always true' do
- subject.should be_available
+ it 'is true if there is a file in options' do
+ subject.should be_available(true, :path => '.guard_result')
+ end
+
+ it 'is false if there is no path in options' do
+ subject.should_not be_available
end
end
@@ -26,6 +30,7 @@
# specified. So, we just don't do anything in .notify if there's no path.
it 'does not write to a file if no path is specified' do
subject.should_not_receive(:write)
+ ::Guard::UI.should_receive(:error).with ":file notifier requires a :path option"
subject.notify('success', 'any title', 'any message', 'any image', { })
end
Something went wrong with that request. Please try again.