diff --git a/core/method/fixtures/classes.rb b/core/method/fixtures/classes.rb index 50daa773e1..464a519aea 100644 --- a/core/method/fixtures/classes.rb +++ b/core/method/fixtures/classes.rb @@ -84,6 +84,12 @@ def one_req_one_opt_with_splat_and_block(a, b=nil, *c, &blk); end def two_req_one_opt_with_splat_and_block(a, b, c=nil, *d, &blk); end def one_req_two_opt_with_splat_and_block(a, b=nil, c=nil, *d, &blk); end + def my_public_method; end + def my_protected_method; end + def my_private_method; end + protected :my_protected_method + private :my_private_method + define_method(:zero_defined_method, Proc.new {||}) define_method(:zero_with_splat_defined_method, Proc.new {|*x|}) define_method(:one_req_defined_method, Proc.new {|x|}) diff --git a/core/method/private_spec.rb b/core/method/private_spec.rb new file mode 100644 index 0000000000..8bd474b87a --- /dev/null +++ b/core/method/private_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "Method#private?" do + it "returns false when the method is public" do + obj = MethodSpecs::Methods.new + obj.method(:my_public_method).private?.should == false + end + + it "returns false when the method is protected" do + obj = MethodSpecs::Methods.new + obj.method(:my_protected_method).private?.should == false + end + + it "returns true when the method is private" do + obj = MethodSpecs::Methods.new + obj.method(:my_private_method).private?.should == true + end + end +end diff --git a/core/method/protected_spec.rb b/core/method/protected_spec.rb new file mode 100644 index 0000000000..c8d1d4138b --- /dev/null +++ b/core/method/protected_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "Method#protected?" do + it "returns false when the method is public" do + obj = MethodSpecs::Methods.new + obj.method(:my_public_method).protected?.should == false + end + + it "returns true when the method is protected" do + obj = MethodSpecs::Methods.new + obj.method(:my_protected_method).protected?.should == true + end + + it "returns false when the method is private" do + obj = MethodSpecs::Methods.new + obj.method(:my_private_method).protected?.should == false + end + end +end diff --git a/core/method/public_spec.rb b/core/method/public_spec.rb new file mode 100644 index 0000000000..9a191e4bf7 --- /dev/null +++ b/core/method/public_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "Method#public?" do + it "returns true when the method is public" do + obj = MethodSpecs::Methods.new + obj.method(:my_public_method).public?.should == true + end + + it "returns false when the method is protected" do + obj = MethodSpecs::Methods.new + obj.method(:my_protected_method).public?.should == false + end + + it "returns false when the method is private" do + obj = MethodSpecs::Methods.new + obj.method(:my_private_method).public?.should == false + end + end +end diff --git a/core/unboundmethod/fixtures/classes.rb b/core/unboundmethod/fixtures/classes.rb index 1f466e39d8..6ab958d447 100644 --- a/core/unboundmethod/fixtures/classes.rb +++ b/core/unboundmethod/fixtures/classes.rb @@ -53,6 +53,12 @@ def neg_four(a, b, *c, &d); end def discard_1(); :discard; end def discard_2(); :discard; end + + def my_public_method; end + def my_protected_method; end + def my_private_method; end + protected :my_protected_method + private :my_private_method end class Parent diff --git a/core/unboundmethod/private_spec.rb b/core/unboundmethod/private_spec.rb new file mode 100644 index 0000000000..4c30981a12 --- /dev/null +++ b/core/unboundmethod/private_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "UnboundMethod#private?" do + it "returns false when the method is public" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_public_method).unbind.private?.should == false + end + + it "returns false when the method is protected" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_protected_method).unbind.private?.should == false + end + + it "returns true when the method is private" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_private_method).unbind.private?.should == true + end + end +end diff --git a/core/unboundmethod/protected_spec.rb b/core/unboundmethod/protected_spec.rb new file mode 100644 index 0000000000..32e80a640e --- /dev/null +++ b/core/unboundmethod/protected_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "UnboundMethod#protected?" do + it "returns false when the method is public" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_public_method).unbind.protected?.should == false + end + + it "returns true when the method is protected" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_protected_method).unbind.protected?.should == true + end + + it "returns false when the method is private" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_private_method).unbind.protected?.should == false + end + end +end diff --git a/core/unboundmethod/public_spec.rb b/core/unboundmethod/public_spec.rb new file mode 100644 index 0000000000..62bc6de414 --- /dev/null +++ b/core/unboundmethod/public_spec.rb @@ -0,0 +1,21 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "3.1" do + describe "UnboundMethod#public?" do + it "returns true when the method is public" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_public_method).unbind.public?.should == true + end + + it "returns false when the method is protected" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_protected_method).unbind.public?.should == false + end + + it "returns false when the method is private" do + obj = UnboundMethodSpecs::Methods.new + obj.method(:my_private_method).unbind.public?.should == false + end + end +end