diff options
Diffstat (limited to 'spec/ruby/core/module/ancestors_spec.rb')
| -rw-r--r-- | spec/ruby/core/module/ancestors_spec.rb | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/spec/ruby/core/module/ancestors_spec.rb b/spec/ruby/core/module/ancestors_spec.rb index 5e4c196206..f85884a4f3 100644 --- a/spec/ruby/core/module/ancestors_spec.rb +++ b/spec/ruby/core/module/ancestors_spec.rb @@ -7,27 +7,45 @@ describe "Module#ancestors" do ModuleSpecs.ancestors.should == [ModuleSpecs] ModuleSpecs::Basic.ancestors.should == [ModuleSpecs::Basic] ModuleSpecs::Super.ancestors.should == [ModuleSpecs::Super, ModuleSpecs::Basic] - ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should == - [ModuleSpecs::Parent, Object, Kernel, BasicObject] - ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should == - [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject] + if defined?(Ruby::Box) && Ruby::Box.enabled? + ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should == + [ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject] + ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should == + [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject] + else + ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should == + [ModuleSpecs::Parent, Object, Kernel, BasicObject] + ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should == + [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject] + end end it "returns only modules and classes" do - class << ModuleSpecs::Child; self; end.ancestors.should include(ModuleSpecs::Internal, Class, Module, Object, Kernel) + class << ModuleSpecs::Child; self; end.ancestors.to_set.should >= Set[ModuleSpecs::Internal, Class, Module, Object, Kernel] end it "has 1 entry per module or class" do ModuleSpecs::Parent.ancestors.should == ModuleSpecs::Parent.ancestors.uniq end + it "returns a module that is included later into a nested module as well" do + m1 = Module.new + m2 = Module.new + m3 = Module.new do + include m2 + end + m2.include m1 # should be after m3 includes m2 + + m3.ancestors.should == [m3, m2, m1] + end + describe "when called on a singleton class" do it "includes the singleton classes of ancestors" do parent = Class.new child = Class.new(parent) schild = child.singleton_class - schild.ancestors.should include(schild, + schild.ancestors.to_set.should >= Set[schild, parent.singleton_class, Object.singleton_class, BasicObject.singleton_class, @@ -35,14 +53,14 @@ describe "Module#ancestors" do Module, Object, Kernel, - BasicObject) + BasicObject] end describe 'for a standalone module' do it 'does not include Class' do s_mod = ModuleSpecs.singleton_class - s_mod.ancestors.should_not include(Class) + s_mod.ancestors.should_not.include?(Class) end it 'does not include other singleton classes' do @@ -51,19 +69,19 @@ describe "Module#ancestors" do s_object = Object.singleton_class s_basic_object = BasicObject.singleton_class - s_standalone_mod.ancestors.should_not include(s_module, s_object, s_basic_object) + (s_standalone_mod.ancestors & [s_module, s_object, s_basic_object]).should.empty? end it 'includes its own singleton class' do s_mod = ModuleSpecs.singleton_class - s_mod.ancestors.should include(s_mod) + s_mod.ancestors.should.include?(s_mod) end it 'includes standard chain' do s_mod = ModuleSpecs.singleton_class - s_mod.ancestors.should include(Module, Object, Kernel, BasicObject) + s_mod.ancestors.to_set.should >= Set[Module, Object, Kernel, BasicObject] end end end |
