summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/kernel_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <[email protected]>2024-02-05 16:29:57 +0100
committerBenoit Daloze <[email protected]>2024-02-05 16:29:57 +0100
commit40642cd3bc581d3bb402ea5e8e61cdfb868b4f68 (patch)
tree077cc3ac94f880ce3c8c98322331c01cb1cc9cb8 /spec/ruby/optional/capi/kernel_spec.rb
parentabe07d4bf5f2f848b22e511a647a85c878066adb (diff)
Update to ruby/spec@3fc4444
Diffstat (limited to 'spec/ruby/optional/capi/kernel_spec.rb')
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb43
1 files changed, 39 insertions, 4 deletions
diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb
index 17c49b2155..3b61d4f0f1 100644
--- a/spec/ruby/optional/capi/kernel_spec.rb
+++ b/spec/ruby/optional/capi/kernel_spec.rb
@@ -606,12 +606,12 @@ describe "C-API Kernel function" do
it "calls a private method" do
object = CApiKernelSpecs::ClassWithPrivateMethod.new
- @s.rb_funcallv(object, :private_method, []).should == 0
+ @s.rb_funcallv(object, :private_method, []).should == :private
end
it "calls a protected method" do
object = CApiKernelSpecs::ClassWithProtectedMethod.new
- @s.rb_funcallv(object, :protected_method, []).should == 0
+ @s.rb_funcallv(object, :protected_method, []).should == :protected
end
end
@@ -629,12 +629,12 @@ describe "C-API Kernel function" do
it "calls a private method" do
object = CApiKernelSpecs::ClassWithPrivateMethod.new
- @s.rb_funcallv_kw(object, :private_method, [{}]).should == 0
+ @s.rb_funcallv_kw(object, :private_method, [{}]).should == :private
end
it "calls a protected method" do
object = CApiKernelSpecs::ClassWithProtectedMethod.new
- @s.rb_funcallv_kw(object, :protected_method, [{}]).should == 0
+ @s.rb_funcallv_kw(object, :protected_method, [{}]).should == :protected
end
it "raises TypeError if the last argument is not a Hash" do
@@ -752,4 +752,39 @@ describe "C-API Kernel function" do
}.should raise_error(NoMethodError, /protected/)
end
end
+
+ describe "rb_check_funcall" do
+ it "calls a method" do
+ @s.rb_check_funcall(1, :+, [2]).should == 3
+ end
+
+ it "returns Qundef if the method is not defined" do
+ obj = Object.new
+ @s.rb_check_funcall(obj, :foo, []).should == :Qundef
+ end
+
+ it "uses #respond_to? to check if the method is defined" do
+ ScratchPad.record []
+ obj = Object.new
+ def obj.respond_to?(name, priv)
+ ScratchPad << name
+ name == :foo || super
+ end
+ def obj.method_missing(name, *args)
+ name == :foo ? [name, 42] : super
+ end
+ @s.rb_check_funcall(obj, :foo, []).should == [:foo, 42]
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it "calls a private method" do
+ object = CApiKernelSpecs::ClassWithPrivateMethod.new
+ @s.rb_check_funcall(object, :private_method, []).should == :private
+ end
+
+ it "calls a protected method" do
+ object = CApiKernelSpecs::ClassWithProtectedMethod.new
+ @s.rb_check_funcall(object, :protected_method, []).should == :protected
+ end
+ end
end