Permalink
Browse files

Merge branch 'master' of github.com:guard/guard

  • Loading branch information...
2 parents 1747f66 + 973aba4 commit 85ed0f82175c9a4ae87f9d7d6e9b5a1ceaa98114 Thibaud Guillaume-Gentil committed May 28, 2011
Showing with 48 additions and 0 deletions.
  1. +1 −0 Gemfile
  2. +24 −0 lib/guard/notifier.rb
  3. +16 −0 spec/guard/notifier_spec.rb
  4. +7 −0 spec/support/gems_helper.rb
View
1 Gemfile
@@ -15,4 +15,5 @@ end
if Config::CONFIG['target_os'] =~ /mswin|mingw/i
gem 'win32console', :require => false
gem 'rb-fchange', '>= 0.0.2', :require => false
+ gem 'rb-notifu', '>= 0.0.4', :require => false
end
View
24 lib/guard/notifier.rb
@@ -16,6 +16,8 @@ def self.turn_on
require_growl
when /linux/i
require_libnotify
+ when /mswin|mingw/i
+ require_rbnotifu
end
end
@@ -30,6 +32,9 @@ def self.notify(message, options = {})
when /linux/i
require_libnotify # need for guard-rspec formatter that is called out of guard scope
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
+ when /mswin|mingw/i
+ require_rbnotifu
+ Notifu.show :message => message, :title => title, :type => image_level(image), :time => 3
end
end
end
@@ -55,6 +60,19 @@ def self.image_path(image)
end
end
+ def self.image_level(image)
+ case image
+ when :failed
+ :error
+ when :pending
+ :warn
+ when :success
+ :info
+ else
+ :info
+ end
+ end
+
def self.require_growl
require 'growl'
rescue LoadError
@@ -69,5 +87,11 @@ def self.require_libnotify
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
end
+ def self.require_rbnotifu
+ require 'rb-notifu'
+ rescue LoadError
+ turn_off
+ UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile"
+ end
end
end
View
16 spec/guard/notifier_spec.rb
@@ -36,6 +36,22 @@
it { should_not be_enabled }
end
end
+
+ if windows?
+ if rbnotifu_installed?
+ it "uses rb-notifu on Windows" do
+ @result = -1
+ Notifu::show :message => "great", :title => 'Guard' do |status|
+ @result = status
+ end
+ sleep 1.5
+ Notifu::ERRORS.include?(@result).should be_false
+ end
+ else
+ it { should_not be_enabled }
+ end
+ end
+
end
describe ".turn_off" do
View
7 spec/support/gems_helper.rb
@@ -10,4 +10,11 @@ def libnotify_installed?
true
rescue LoadError
false
+end
+
+def rbnotifu_installed?
+ require 'rb-notifu'
+ true
+rescue LoadError
+ false
end

0 comments on commit 85ed0f8

Please sign in to comment.