1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Improved test coverage for when require is called twice with same args

This commit is contained in:
Ryan McGeary 2008-05-10 19:26:27 -04:00
parent 913e1094d5
commit 3fe29b73dd
2 changed files with 24 additions and 20 deletions

View file

@ -140,28 +140,27 @@ 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
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
end
else
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
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
end
end
private

View file

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