1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,52 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "DelegateClass.instance_method" do
before :all do
@klass = DelegateSpecs::DelegateClass
@obj = @klass.new(DelegateSpecs::Simple.new)
end
it "returns a method object for public instance methods of the delegated class" do
m = @klass.instance_method(:pub)
m.should be_an_instance_of(UnboundMethod)
m.bind(@obj).call.should == :foo
end
it "returns a method object for protected instance methods of the delegated class" do
m = @klass.instance_method(:prot)
m.should be_an_instance_of(UnboundMethod)
m.bind(@obj).call.should == :protected
end
it "raises a NameError for a private instance methods of the delegated class" do
lambda {
@klass.instance_method(:priv)
}.should raise_error(NameError)
end
it "returns a method object for public instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra)
m.should be_an_instance_of(UnboundMethod)
m.bind(@obj).call.should == :cheese
end
it "returns a method object for protected instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra_protected)
m.should be_an_instance_of(UnboundMethod)
m.bind(@obj).call.should == :baz
end
it "returns a method object for private instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra_private)
m.should be_an_instance_of(UnboundMethod)
m.bind(@obj).call.should == :bar
end
it "raises a NameError for an invalid method name" do
lambda {
@klass.instance_method(:invalid_and_silly_method_name)
}.should raise_error(NameError)
end
end

View file

@ -0,0 +1,26 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "DelegateClass.instance_methods" do
before :all do
@methods = DelegateSpecs::DelegateClass.instance_methods
end
it "includes all public methods of the delegated class" do
@methods.should include :pub
end
it "includes all protected methods of the delegated class" do
@methods.should include :prot
end
it "includes instance methods of the DelegateClass class" do
@methods.should include :extra
@methods.should include :extra_protected
end
it "does not include private methods" do
@methods.should_not include :priv
@methods.should_not include :extra_private
end
end

View file

@ -0,0 +1,23 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "DelegateClass.private_instance_methods" do
before :all do
@methods = DelegateSpecs::DelegateClass.private_instance_methods
end
it "does not include any instance methods of the delegated class" do
@methods.should_not include :pub
@methods.should_not include :prot
@methods.should_not include :priv # since these are not forwarded...
end
it "includes private instance methods of the DelegateClass class" do
@methods.should include :extra_private
end
it "does not include public or protected instance methods of the DelegateClass class" do
@methods.should_not include :extra
@methods.should_not include :extra_protected
end
end

View file

@ -0,0 +1,29 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "DelegateClass.protected_instance_methods" do
before :all do
@methods = DelegateSpecs::DelegateClass.protected_instance_methods
end
it "does not include public methods of the delegated class" do
@methods.should_not include :pub
end
it "includes the protected methods of the delegated class" do
@methods.should include :prot
end
it "includes protected instance methods of the DelegateClass class" do
@methods.should include :extra_protected
end
it "does not include public instance methods of the DelegateClass class" do
@methods.should_not include :extra
end
it "does not include private methods" do
@methods.should_not include :priv
@methods.should_not include :extra_private
end
end

View file

@ -0,0 +1,25 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
describe "DelegateClass.public_instance_methods" do
before :all do
@methods = DelegateSpecs::DelegateClass.public_instance_methods
end
it "includes all public methods of the delegated class" do
@methods.should include :pub
end
it "does not include the protected methods of the delegated class" do
@methods.should_not include :prot
end
it "includes public instance methods of the DelegateClass class" do
@methods.should include :extra
end
it "does not include private methods" do
@methods.should_not include :priv
@methods.should_not include :extra_private
end
end

View file

@ -0,0 +1,23 @@
require 'delegate'
describe "DelegateClass#respond_to_missing?" do
it "is used for respond_to? behavior of late-bound delegated methods" do
# From jruby/jruby#3151:
# DelegateClass subtracts Delegate's public API from the target class's instance_methods
# to determine which methods to eagerly delegate. If respond_to_missing? shows up in
# instance_methods, it will get delegated and skip the delegate-aware implementation
# in Delegate. Any methods that must be delegated through method_missing, like methods
# defined after the DelegateClass is created, will fail to dispatch properly.
cls = Class.new
dcls = DelegateClass(cls)
cdcls = Class.new(dcls)
cdcls_obj = cdcls.new(cls.new)
cdcls_obj.respond_to?(:foo).should == false
cls.class_eval { def foo; end }
cdcls_obj.respond_to?(:foo).should == true
end
end