Permalink
Browse files

Now returning nil when trying to instantiate Growl when not installed

This form of notification should never be the primary choice, therefore
it is not crucial that they are created
  • Loading branch information...
1 parent 3de63a0 commit 03541cf37cd473d7f1f84aa0ede74400b0f47607 @tj committed Apr 8, 2009
Showing with 10 additions and 2 deletions.
  1. +4 −2 lib/growl/growl.rb
  2. +6 −0 spec/growl_spec.rb
View
@@ -26,7 +26,7 @@ def exec *args
# Return the version triple of the binary.
def version
- `#{BIN} --version`.split[1]
+ @version ||= `#{BIN} --version`.split[1]
end
##
@@ -37,9 +37,10 @@ def installed?
end
##
- # Return an instance of Growl::Base.
+ # Return an instance of Growl::Base or nil when not installed.
def new *args, &block
+ return unless installed?
Base.new *args, &block
end
@@ -138,5 +139,6 @@ def self.switches
end
def Growl options = {}, &block
+ return unless Growl.installed?
Growl.new(options, &block).run
end
View
@@ -26,6 +26,12 @@
it "should accept a hash" do
Growl :message => 'Invoked via Growl with hash', :icon => 'jpeg', :title => 'Growl'
end
+
+ it "should return nil when not installed" do
+ Growl.stub!(:installed?).and_return(false)
+ Growl.new.should be_nil
+ lambda { Growl :message => 'I should never show :)' }.should_not raise_error
+ end
end
describe "#run" do

0 comments on commit 03541cf

Please sign in to comment.