summaryrefslogtreecommitdiff
path: root/test/test_delegate.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-02-03 12:29:37 +0100
committerJeremy Evans <code@jeremyevans.net>2020-02-03 08:16:22 -0800
commitf2552216d43040cd42bbb9fd484eab6c70856fe6 (patch)
tree417634fff2c49a9e2cf6f68733053ac103b735be /test/test_delegate.rb
parent11963da9e8e98821860fbb0c0f2adc118860c814 (diff)
Fix SimpleDelegator respond_to? regression
In 2.6, SimpleDelegator would always use the target `respond_to?` In 2.7.0 it doesn't if the target does not inherit from Object. This breaks compatibility for delegated objects that inherit from BasicObject and redefine `respond_to?`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2875
Diffstat (limited to 'test/test_delegate.rb')
-rw-r--r--test/test_delegate.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/test_delegate.rb b/test/test_delegate.rb
index 9c47743..4a3445f 100644
--- a/test/test_delegate.rb
+++ b/test/test_delegate.rb
@@ -344,6 +344,20 @@ class TestDelegateClass < Test::Unit::TestCase
assert_raise(NoMethodError, /undefined method `foo' for/) { delegate.foo }
end
+ def test_basicobject_respond_to
+ o = BasicObject.new
+ def o.bar
+ nil
+ end
+
+ def o.respond_to?(method, include_private=false)
+ return false if method == :bar
+ ::Kernel.instance_method(:respond_to?).bind_call(self, method, include_private)
+ end
+ delegate = SimpleDelegator.new(o)
+ refute delegate.respond_to?(:bar)
+ end
+
def test_keyword_argument
k = EnvUtil.labeled_class("Target") do
def test(a, k:) [a, k]; end