@@ -606,12 +606,12 @@ def sum(a, b)
606
606
607
607
it "calls a private method" do
608
608
object = CApiKernelSpecs ::ClassWithPrivateMethod . new
609
- @s . rb_funcallv ( object , :private_method , [ ] ) . should == 0
609
+ @s . rb_funcallv ( object , :private_method , [ ] ) . should == :private
610
610
end
611
611
612
612
it "calls a protected method" do
613
613
object = CApiKernelSpecs ::ClassWithProtectedMethod . new
614
- @s . rb_funcallv ( object , :protected_method , [ ] ) . should == 0
614
+ @s . rb_funcallv ( object , :protected_method , [ ] ) . should == :protected
615
615
end
616
616
end
617
617
@@ -629,12 +629,12 @@ def m(*args, **kwargs)
629
629
630
630
it "calls a private method" do
631
631
object = CApiKernelSpecs ::ClassWithPrivateMethod . new
632
- @s . rb_funcallv_kw ( object , :private_method , [ { } ] ) . should == 0
632
+ @s . rb_funcallv_kw ( object , :private_method , [ { } ] ) . should == :private
633
633
end
634
634
635
635
it "calls a protected method" do
636
636
object = CApiKernelSpecs ::ClassWithProtectedMethod . new
637
- @s . rb_funcallv_kw ( object , :protected_method , [ { } ] ) . should == 0
637
+ @s . rb_funcallv_kw ( object , :protected_method , [ { } ] ) . should == :protected
638
638
end
639
639
640
640
it "raises TypeError if the last argument is not a Hash" do
@@ -752,4 +752,39 @@ def method_public(*args, **kw, &block); [args, kw, block.call] end
752
752
} . should raise_error ( NoMethodError , /protected/ )
753
753
end
754
754
end
755
+
756
+ describe "rb_check_funcall" do
757
+ it "calls a method" do
758
+ @s . rb_check_funcall ( 1 , :+ , [ 2 ] ) . should == 3
759
+ end
760
+
761
+ it "returns Qundef if the method is not defined" do
762
+ obj = Object . new
763
+ @s . rb_check_funcall ( obj , :foo , [ ] ) . should == :Qundef
764
+ end
765
+
766
+ it "uses #respond_to? to check if the method is defined" do
767
+ ScratchPad . record [ ]
768
+ obj = Object . new
769
+ def obj . respond_to? ( name , priv )
770
+ ScratchPad << name
771
+ name == :foo || super
772
+ end
773
+ def obj . method_missing ( name , *args )
774
+ name == :foo ? [ name , 42 ] : super
775
+ end
776
+ @s . rb_check_funcall ( obj , :foo , [ ] ) . should == [ :foo , 42 ]
777
+ ScratchPad . recorded . should == [ :foo ]
778
+ end
779
+
780
+ it "calls a private method" do
781
+ object = CApiKernelSpecs ::ClassWithPrivateMethod . new
782
+ @s . rb_check_funcall ( object , :private_method , [ ] ) . should == :private
783
+ end
784
+
785
+ it "calls a protected method" do
786
+ object = CApiKernelSpecs ::ClassWithProtectedMethod . new
787
+ @s . rb_check_funcall ( object , :protected_method , [ ] ) . should == :protected
788
+ end
789
+ end
755
790
end
0 commit comments