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