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:
parent
913e1094d5
commit
3fe29b73dd
2 changed files with 24 additions and 20 deletions
|
@ -140,27 +140,26 @@ module Capistrano
|
||||||
def require(*args) #:nodoc:
|
def require(*args) #:nodoc:
|
||||||
# look to see if this specific configuration instance has ever seen
|
# look to see if this specific configuration instance has ever seen
|
||||||
# these arguments to require before
|
# these arguments to require before
|
||||||
if !@loaded_features.include?(args)
|
if @loaded_features.include?(args)
|
||||||
@loaded_features << 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
|
result = super
|
||||||
original_instance, self.class.instance = self.class.instance, self
|
if !result # file has been required previously, load up the remembered recipes
|
||||||
original_feature, self.class.current_feature = self.class.current_feature, args
|
list = self.class.recipes_per_feature[args] || []
|
||||||
|
list.each { |options| load(options.merge(:reloading => true)) }
|
||||||
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
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -117,6 +117,11 @@ class ConfigurationLoadingTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
def test_require_in_multiple_instances_should_load_recipes_in_each_instance
|
||||||
config2 = MockConfig.new
|
config2 = MockConfig.new
|
||||||
@config.require "#{File.dirname(__FILE__)}/../fixtures/custom"
|
@config.require "#{File.dirname(__FILE__)}/../fixtures/custom"
|
||||||
|
@ -124,4 +129,4 @@ class ConfigurationLoadingTest < Test::Unit::TestCase
|
||||||
assert_equal :custom, @config.ping
|
assert_equal :custom, @config.ping
|
||||||
assert_equal :custom, config2.ping
|
assert_equal :custom, config2.ping
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue