From 3fe29b73dd966d1e99f7d1151b19bc8b793db476 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Sat, 10 May 2008 19:26:27 -0400 Subject: [PATCH] Improved test coverage for when require is called twice with same args --- lib/capistrano/configuration/loading.rb | 37 ++++++++++++------------- test/configuration/loading_test.rb | 7 ++++- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/capistrano/configuration/loading.rb b/lib/capistrano/configuration/loading.rb index 37d9b1bb..fc7fece8 100644 --- a/lib/capistrano/configuration/loading.rb +++ b/lib/capistrano/configuration/loading.rb @@ -140,27 +140,26 @@ module Capistrano def require(*args) #:nodoc: # look to see if this specific configuration instance has ever seen # these arguments to require before - if !@loaded_features.include?(args) - @loaded_features << args + if @loaded_features.include?(args) + return false + end + + @loaded_features << args + begin + original_instance, self.class.instance = self.class.instance, self + original_feature, self.class.current_feature = self.class.current_feature, args - begin - original_instance, self.class.instance = self.class.instance, self - original_feature, self.class.current_feature = self.class.current_feature, args - - result = super - if !result # file has been required previously, load up the remembered recipes - list = self.class.recipes_per_feature[args] || [] - list.each { |options| load(options.merge(:reloading => true)) } - end - - return result - ensure - # restore the original, so that require's can be nested - self.class.instance = original_instance - self.class.current_feature = original_feature + result = super + if !result # file has been required previously, load up the remembered recipes + list = self.class.recipes_per_feature[args] || [] + list.each { |options| load(options.merge(:reloading => true)) } end - else - return false + + return result + ensure + # restore the original, so that require's can be nested + self.class.instance = original_instance + self.class.current_feature = original_feature end end diff --git a/test/configuration/loading_test.rb b/test/configuration/loading_test.rb index 35cf96ed..f2e99abf 100644 --- a/test/configuration/loading_test.rb +++ b/test/configuration/loading_test.rb @@ -117,6 +117,11 @@ class ConfigurationLoadingTest < Test::Unit::TestCase end end + def test_require_from_config_should_return_false_when_called_a_second_time_with_same_args + assert @config.require "#{File.dirname(__FILE__)}/../fixtures/custom" + assert_equal false, @config.require("#{File.dirname(__FILE__)}/../fixtures/custom") + end + def test_require_in_multiple_instances_should_load_recipes_in_each_instance config2 = MockConfig.new @config.require "#{File.dirname(__FILE__)}/../fixtures/custom" @@ -124,4 +129,4 @@ class ConfigurationLoadingTest < Test::Unit::TestCase assert_equal :custom, @config.ping assert_equal :custom, config2.ping end -end \ No newline at end of file +end