Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs for prepend modifying ancestor chain #1136

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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