-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements [Feature #18273] Returns an array containing the receiver's direct subclasses without singleton classes.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require_relative '../../spec_helper' | ||
require_relative '../module/fixtures/classes' | ||
|
||
ruby_version_is '3.1' do | ||
describe "Class#subclasses" do | ||
it "returns a list of classes directly inheriting from self" do | ||
assert_subclasses(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2]) | ||
end | ||
|
||
it "does not return included modules" do | ||
parent = Class.new | ||
child = Class.new(parent) | ||
mod = Module.new | ||
parent.include(mod) | ||
|
||
assert_subclasses(parent, [child]) | ||
end | ||
|
||
it "does not return singleton classes" do | ||
a = Class.new | ||
|
||
a_obj = a.new | ||
def a_obj.force_singleton_class | ||
42 | ||
end | ||
|
||
a.subclasses.should_not include(a_obj.singleton_class) | ||
end | ||
|
||
it "has 1 entry per module or class" do | ||
ModuleSpecs::Parent.subclasses.should == ModuleSpecs::Parent.subclasses.uniq | ||
end | ||
|
||
def assert_subclasses(mod,subclasses) | ||
mod.subclasses.sort_by(&:inspect).should == subclasses.sort_by(&:inspect) | ||
end | ||
end | ||
end |