Don't modify a frozen hash.

This commit is contained in:
Rémy Coutable 2011-05-07 18:40:13 +02:00
parent 5352528530
commit 9cfe8d3635
4 changed files with 13 additions and 9 deletions

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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