Skip to content

Fix for capture not working #175

Merged
merged 1 commit into from Mar 8, 2012
View
13 lib/capistrano/configuration/namespaces.rb
@@ -176,6 +176,8 @@ class Namespace
def initialize(name, parent)
@parent = parent
@name = name
+
+ explicitly_define_clashing_kernel_methods
end
def role(*args)
@@ -197,6 +199,17 @@ def method_missing(sym, *args, &block)
include Capistrano::Configuration::AliasTask
include Capistrano::Configuration::Namespaces
undef :desc, :next_description
+
+ protected
+ def explicitly_define_clashing_kernel_methods
+ (parent.public_methods & Kernel.methods).each do |m|
+ next if self.method(m).owner == self.class
+ if parent.method(m).owner == parent.class
+ metaclass = class << self; self; end
+ metaclass.send(:define_method, m) {|*args, &block| parent.send(m, *args, &block)}
+ end
+ end
+ end
end
end
end
View
21 test/configuration/namespace_dsl_test.rb
@@ -308,4 +308,25 @@ def test_find_task_should_return_nil_when_empty_inner_task
end
assert_nil @config.find_task("outer::inner")
end
+
+ def test_kernel_method_clashing_should_not_affect_method_delegation_to_parent
+ @config.class.class_eval do
+ def some_weird_method() 'config' end
+ end
+
+ @config.namespace(:clash) {}
+ namespace = @config.namespaces[:clash]
+ assert_equal 'config', namespace.some_weird_method
+
+ Kernel.module_eval do
+ def some_weird_method() 'kernel' end
+ end
+
+ @config.namespace(:clash2) {}
+ namespace = @config.namespaces[:clash2]
+ assert_equal 'config', namespace.some_weird_method
+
+ Kernel.send :remove_method, :some_weird_method
+ @config.class.send :remove_method, :some_weird_method
+ end
end
Something went wrong with that request. Please try again.