Permalink
Browse files

Merge pull request #175 from siannopollo/master

Fix for `capture` not working (ActiveSupport poison)
  • Loading branch information...
2 parents 6543a8f + 55a6ef2 commit 7de5eb03677dcfb643277e6cf9defbdb436b7ea4 @leehambley leehambley committed Mar 8, 2012
Showing with 34 additions and 0 deletions.
  1. +13 −0 lib/capistrano/configuration/namespaces.rb
  2. +21 −0 test/configuration/namespace_dsl_test.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
@@ -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

1 comment on commit 7de5eb0

kuinak commented on 7de5eb0 Mar 28, 2012

I ran into this problem as well and switched to this version hoping it would solve the issue. However, it's still calling Kernel#capture. I believe this is because the owner of the #capture method is the module Capistrano::Configuration::Actions::Inspect, whereas the parent class is Capistrano::Configuration, which includes this module. Because of this, line 207 returns false and the method never gets defined explicitly.

Please sign in to comment.