From 9cfe8d3635586bca37281b433e20048a4ad1dd0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Sat, 7 May 2011 18:40:13 +0200 Subject: [PATCH] Don't modify a frozen hash. --- lib/guard.rb | 7 +++---- spec/guard/notifier_spec.rb | 6 +++--- spec/guard_spec.rb | 8 +++++++- spec/spec_helper.rb | 1 - 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/guard.rb b/lib/guard.rb index 12c35a9..c5fee7d 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -16,8 +16,7 @@ module Guard @listener = Listener.select_and_init @guards = [] - options[:notify] = false if ENV["GUARD_NOTIFY"] == 'false' - options[:notify] ? Notifier.turn_on : Notifier.turn_off + !@options[:notify] || ENV["GUARD_NOTIFY"] == 'false' ? Notifier.turn_off : Notifier.turn_on self end @@ -61,7 +60,7 @@ module Guard guard.send(task_to_supervise, *args) rescue Exception UI.error("#{guard.class.name} guard failed to achieve its <#{task_to_supervise.to_s}> command: #{$!}") - ::Guard.guards.delete guard + guards.delete guard UI.info("Guard #{guard.class.name} has just been fired") return $! end @@ -83,7 +82,7 @@ module Guard def get_guard_class(name) try_to_load_gem name - self.const_get(self.constants.find{|klass_name| klass_name.to_s.downcase == name.downcase }) + self.const_get(self.constants.find{ |klass_name| klass_name.to_s.downcase == name.downcase }) rescue TypeError UI.error "Could not find load find gem 'guard-#{name}' or find class Guard::#{name}" end diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index e09622c..5a228e1 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -38,14 +38,14 @@ describe Guard::Notifier do end describe ".turn_off" do + before(:each) { subject.turn_off } + if mac? && growl_installed? it "does nothing" do Growl.should_not_receive(:notify) subject.notify 'great', :title => 'Guard' end - end - - if linux? && libnotify_installed? + elsif linux? && libnotify_installed? it "does nothing" do Libnotify.should_not_receive(:show) subject.notify 'great', :title => 'Guard' diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index bf3faa8..c5b6a49 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -4,6 +4,12 @@ describe Guard do describe "Class Methods" do describe ".setup" do + before(:each) do + # set ENV["GUARD_NOTIFY"] to nil in case the user has ENV["GUARD_NOTIFY"] = 'false' set + @old_env_guard_notify = ENV["GUARD_NOTIFY"] + ENV["GUARD_NOTIFY"] = nil + end + after(:each) { ENV["GUARD_NOTIFY"] = @old_env_guard_notify } subject { ::Guard.setup } it "should retrieve itself for chaining" do @@ -36,7 +42,7 @@ describe Guard do it "should turn off notifier if env[GUARD_NOTIFY] is false" do ::Guard::Notifier.should_receive(:turn_off) ENV["GUARD_NOTIFY"] = 'false' - ::Guard.setup(:notify => true) + ::Guard.setup({ :notify => true }.freeze) ENV["GUARD_NOTIFY"] = nil end 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