Permalink
Browse files

Make urgency configurable for libnotify/notifysend

- Change default urgency for libnotify to normal and low to match
  notifysend's defaults.
  • Loading branch information...
1 parent 17dae36 commit a2b35eb919d71292b927d337300459079ed0f352 @viking committed Mar 28, 2012
@@ -17,7 +17,7 @@ module Notifier
# notification :libnotify
#
# @example Add the `:libnotify` notifier with configuration options to your `Guardfile`
- # notification :libnotify, :timeout => 5, :transient => true, :append => false
+ # notification :libnotify, :timeout => 5, :transient => true, :append => false, :urgency => :critical
#
module Libnotify
extend self
@@ -64,12 +64,13 @@ def available?(silent = false)
def notify(type, title, message, image, options = { })
require 'libnotify'
- ::Libnotify.show(DEFAULTS.merge(options).merge({
- :urgency => libnotify_urgency(type),
+ options = DEFAULTS.merge(options).merge({
:summary => title,
:body => message,
:icon_path => image
- }))
+ })
+ options[:urgency] ||= libnotify_urgency(type)
+ ::Libnotify.show(options)
end
private
@@ -83,8 +84,6 @@ def notify(type, title, message, image, options = { })
def libnotify_urgency(type)
case type
when 'failed'
- :critical
- when 'pending'
:normal
else
:low
@@ -46,10 +46,11 @@ def available?(silent = false)
#
def notify(type, title, message, image, options = { })
command = "notify-send '#{title}' '#{message}'"
- system(to_command_string(command, SUPPORTED, DEFAULTS.merge(options).merge({
- :u => notifysend_urgency(type),
+ options = DEFAULTS.merge(options).merge({
:i => image
- })))
+ })
+ options[:u] ||= notifysend_urgency(type)
+ system(to_command_string(command, SUPPORTED, options))
end
private
@@ -45,7 +45,7 @@ def self.show(options) end
end
end
- describe '.nofify' do
+ describe '.notify' do
it 'requires the library again' do
subject.should_receive(:require).with('libnotify').and_return true
subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { })
@@ -72,15 +72,16 @@ def self.show(options) end
:transient => true,
:append => false,
:timeout => 5,
- :urgency => :normal,
+ :urgency => :critical,
:summary => 'Waiting',
:body => 'Waiting for something',
:icon_path => '/tmp/wait.png'
})
subject.notify('pending', 'Waiting', 'Waiting for something', '/tmp/wait.png', {
:transient => true,
:append => false,
- :timeout => 5
+ :timeout => 5,
+ :urgency => :critical
})
end
@@ -89,13 +90,12 @@ def self.show(options) end
:transient => false,
:append => true,
:timeout => 3,
- :urgency => :critical,
+ :urgency => :normal,
:summary => 'Failed',
:body => 'Something failed',
:icon_path => '/tmp/fail.png'
})
subject.notify('failed', 'Failed', 'Something failed', '/tmp/fail.png', {
- :urgency => :extreme,
:summary => 'Duplicate title',
:body => 'Duplicate body',
:icon_path => 'Duplicate icon'
@@ -28,4 +28,33 @@ def self.show(options) end
end
end
end
+
+ describe '.notify' do
+ context 'without additional options' do
+ it 'shows the notification with the default options' do
+ subject.should_receive(:system).with do |command|
+ command.should include("notify-send 'Welcome' 'Welcome to Guard'")
+ command.should include("-i '/tmp/welcome.png'")
+ command.should include("-u 'low'")
+ command.should include("-t '3000'")
+ end
+ subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { })
+ end
+ end
+
+ context 'with additional options' do
+ it 'can override the default options' do
+ subject.should_receive(:system).with do |command|
+ command.should include("notify-send 'Waiting' 'Waiting for something'")
+ command.should include("-i '/tmp/wait.png'")
+ command.should include("-u 'critical'")
+ command.should include("-t '5'")
+ end
+ subject.notify('pending', 'Waiting', 'Waiting for something', '/tmp/wait.png', {
+ :t => 5,
+ :u => :critical
+ })
+ end
+ end
+ end
end

0 comments on commit a2b35eb

Please sign in to comment.