Skip to content

Commit

Permalink
Add specs for prepend modifying ancestor chain
Browse files Browse the repository at this point in the history
  • Loading branch information
dushyantss authored and eregon committed Feb 12, 2024
1 parent 8261185 commit 24a5994
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/module/prepend_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,39 @@ def foo(ary)
klass.ancestors.take(4).should == [klass, submod, mod, Object]
end

# https://bugs.ruby-lang.org/issues/17423
describe "when module already exists in ancestor chain" do
ruby_version_is ""..."3.1" do
it "does not modify the ancestor chain" do
m = Module.new do; end
a = Module.new do; end
b = Class.new do; end

b.include(a)
a.prepend(m)
b.ancestors.take(4).should == [b, m, a, Object]

b.prepend(m)
b.ancestors.take(4).should == [b, m, a, Object]
end
end

ruby_version_is "3.1" do
it "modifies the ancestor chain" do
m = Module.new do; end
a = Module.new do; end
b = Class.new do; end

b.include(a)
a.prepend(m)
b.ancestors.take(4).should == [b, m, a, Object]

b.prepend(m)
b.ancestors.take(5).should == [m, b, m, a, Object]
end
end
end

describe "called on a module" do
describe "included into a class"
it "does not obscure the module's methods from reflective access" do
Expand Down

0 comments on commit 24a5994

Please sign in to comment.