diff --git a/README.markdown b/README.markdown index fd09da1..13b41ec 100644 --- a/README.markdown +++ b/README.markdown @@ -117,7 +117,7 @@ Notifications (growl/libnotify) can be disabled with: ``` bash $ guard --notify false -$ guard -n false # shortcut +$ guard -n f # shortcut ``` Notifications can also be disabled by setting a `GUARD_NOTIFY` environment variable to `false` diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 421cb70..e0a2224 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -3,13 +3,14 @@ require 'pathname' module Guard module Notifier + @enabled = false def self.turn_off - ENV["GUARD_NOTIFY"] = 'false' + @enabled = false end def self.turn_on - ENV["GUARD_NOTIFY"] = 'true' + @enabled = true case Config::CONFIG['target_os'] when /darwin/i require_growl @@ -19,7 +20,7 @@ module Guard end def self.notify(message, options = {}) - unless disabled? + if enabled? image = options[:image] || :success title = options[:title] || "Guard" case Config::CONFIG['target_os'] @@ -31,8 +32,8 @@ module Guard end end - def self.disabled? - ENV["GUARD_NOTIFY"] == 'false' + def self.enabled? + @enabled end private diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 5a228e1..9feea9b 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -5,6 +5,7 @@ describe Guard::Notifier do describe ".notify" do before(:each) { subject.turn_on } + after(:each) { subject.turn_off } if mac? if growl_installed? @@ -17,7 +18,7 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard' end else - it { should be_disabled } + it { should_not be_enabled } end end @@ -32,14 +33,12 @@ describe Guard::Notifier do subject.notify 'great', :title => 'Guard' end else - it { should be_disabled } + it { should_not be_enabled } end end end describe ".turn_off" do - before(:each) { subject.turn_off } - if mac? && growl_installed? it "does nothing" do Growl.should_not_receive(:notify) @@ -52,7 +51,7 @@ describe Guard::Notifier do end end - it { should be_disabled } + it { should_not be_enabled } end end diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index fa17a99..c147f32 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -35,6 +35,7 @@ describe Guard do end it "should turn off notifier if env[GUARD_NOTIFY] is false" do + ENV["GUARD_NOTIFY"] = 'false' ::Guard::Notifier.should_receive(:turn_off) ::Guard.setup(:notify => true) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f69ed16..1520849 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,7 +15,6 @@ RSpec.configure do |config| config.run_all_when_everything_filtered = true config.before(:each) do - Guard::Notifier.turn_off @fixture_path = Pathname.new(File.expand_path('../fixtures/', __FILE__)) end