Permalink
Browse files

Refactorized notifier enabling/disabling

  • Loading branch information...
1 parent 0dcf13d commit f424854e61da2147e8c9d55b73310d012faaa913 @thibaudgg thibaudgg committed May 10, 2011
Showing with 12 additions and 12 deletions.
  1. +1 −1 README.markdown
  2. +6 −5 lib/guard/notifier.rb
  3. +4 −5 spec/guard/notifier_spec.rb
  4. +1 −0 spec/guard_spec.rb
  5. +0 −1 spec/spec_helper.rb
View
@@ -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`
View
@@ -3,13 +3,14 @@
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 @@ def self.turn_on
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 @@ def self.notify(message, options = {})
end
end
- def self.disabled?
- ENV["GUARD_NOTIFY"] == 'false'
+ def self.enabled?
+ @enabled
end
private
@@ -5,6 +5,7 @@
describe ".notify" do
before(:each) { subject.turn_on }
+ after(:each) { subject.turn_off }
if mac?
if growl_installed?
@@ -17,7 +18,7 @@
subject.notify 'great', :title => 'Guard'
end
else
- it { should be_disabled }
+ it { should_not be_enabled }
end
end
@@ -32,14 +33,12 @@
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 @@
end
end
- it { should be_disabled }
+ it { should_not be_enabled }
end
end
View
@@ -35,6 +35,7 @@
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
View
@@ -15,7 +15,6 @@
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

0 comments on commit f424854

Please sign in to comment.