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

Refinement#include and Refinement#prepend have been deprecated

This commit is contained in:
Nobuyoshi Nakada 2021-10-22 13:53:21 +09:00
parent 4446942f1a
commit 9f4f3bd1cc
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

View file

@ -298,63 +298,65 @@ describe "Module#refine" do
result.should == "foo from IncludeMeLater"
end
it "looks in prepended modules from the refinement first" do
refined_class = ModuleSpecs.build_refined_class
ruby_version_is ""..."3.1" do
it "looks in prepended modules from the refinement first" do
refined_class = ModuleSpecs.build_refined_class
refinement = Module.new do
refine refined_class do
include ModuleSpecs::IncludedModule
prepend ModuleSpecs::PrependedModule
refinement = Module.new do
refine refined_class do
include ModuleSpecs::IncludedModule
prepend ModuleSpecs::PrependedModule
def foo; "foo from refinement"; end
def foo; "foo from refinement"; end
end
end
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == "foo from prepended module"
end
it "looks in refinement then" do
refined_class = ModuleSpecs.build_refined_class
refinement = Module.new do
refine(refined_class) do
include ModuleSpecs::IncludedModule
def foo; "foo from refinement"; end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == "foo from prepended module"
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
it "looks in refinement then" do
refined_class = ModuleSpecs.build_refined_class
result.should == "foo from refinement"
end
refinement = Module.new do
refine(refined_class) do
include ModuleSpecs::IncludedModule
it "looks in included modules from the refinement then" do
refined_class = ModuleSpecs.build_refined_class
refinement = Module.new do
refine refined_class do
include ModuleSpecs::IncludedModule
def foo; "foo from refinement"; end
end
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == "foo from refinement"
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
it "looks in included modules from the refinement then" do
refined_class = ModuleSpecs.build_refined_class
result.should == "foo from included module"
refinement = Module.new do
refine refined_class do
include ModuleSpecs::IncludedModule
end
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == "foo from included module"
end
end
it "looks in the class then" do
@ -704,55 +706,57 @@ describe "Module#refine" do
result.should == "foo"
end
it "looks in the refined class from included module" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
ruby_version_is ""..."3.1" do
it "looks in the refined class from included module" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
a = Module.new do
def foo
[:A] + super
a = Module.new do
def foo
[:A] + super
end
end
end
refinement = Module.new do
refine refined_class do
include a
refinement = Module.new do
refine refined_class do
include a
end
end
end
result = nil
Module.new do
using refinement
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == [:A, :C]
end
it "looks in the refined ancestors from included module" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
subclass = Class.new(refined_class)
a = Module.new do
def foo
[:A] + super
result = refined_class.new.foo
end
result.should == [:A, :C]
end
refinement = Module.new do
refine refined_class do
include a
it "looks in the refined ancestors from included module" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
subclass = Class.new(refined_class)
a = Module.new do
def foo
[:A] + super
end
end
refinement = Module.new do
refine refined_class do
include a
end
end
result = nil
Module.new do
using refinement
result = subclass.new.foo
end
result.should == [:A, :C]
end
result = nil
Module.new do
using refinement
result = subclass.new.foo
end
result.should == [:A, :C]
end
# super in a method of a refinement invokes the method in the refined
@ -816,175 +820,177 @@ describe "Module#refine" do
end
end
it "does't have access to active refinements for C from included module" do
refined_class = ModuleSpecs.build_refined_class
ruby_version_is ""..."3.1" do
it "does't have access to active refinements for C from included module" do
refined_class = ModuleSpecs.build_refined_class
a = Module.new do
def foo
super + bar
end
end
refinement = Module.new do
refine refined_class do
include a
def bar
"bar is not seen from A methods"
end
end
end
Module.new do
using refinement
-> {
refined_class.new.foo
}.should raise_error(NameError) { |e| e.name.should == :bar }
end
end
it "does't have access to other active refinements from included module" do
refined_class = ModuleSpecs.build_refined_class
refinement_integer = Module.new do
refine Integer do
def bar
"bar is not seen from A methods"
end
end
end
a = Module.new do
def foo
super + 1.bar
end
end
refinement = Module.new do
refine refined_class do
include a
end
end
Module.new do
using refinement
using refinement_integer
-> {
refined_class.new.foo
}.should raise_error(NameError) { |e| e.name.should == :bar }
end
end
# https://bugs.ruby-lang.org/issues/16977
it "looks in the another active refinement if super called from included modules" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
a = Module.new do
def foo
[:A] + super
end
end
b = Module.new do
def foo
[:B] + super
end
end
refinement_a = Module.new do
refine refined_class do
include a
end
end
refinement_b = Module.new do
refine refined_class do
include b
end
end
result = nil
Module.new do
using refinement_a
using refinement_b
result = refined_class.new.foo
end
result.should == [:B, :A, :C]
end
it "looks in the current active refinement from included modules" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
a = Module.new do
def foo
[:A] + super
end
end
b = Module.new do
def foo
[:B] + super
end
end
refinement = Module.new do
refine refined_class do
a = Module.new do
def foo
[:LAST] + super
super + bar
end
end
end
refinement_a_b = Module.new do
refine refined_class do
include a
include b
refinement = Module.new do
refine refined_class do
include a
def bar
"bar is not seen from A methods"
end
end
end
Module.new do
using refinement
-> {
refined_class.new.foo
}.should raise_error(NameError) { |e| e.name.should == :bar }
end
end
result = nil
Module.new do
using refinement
using refinement_a_b
result = refined_class.new.foo
end
it "does't have access to other active refinements from included module" do
refined_class = ModuleSpecs.build_refined_class
result.should == [:B, :A, :LAST, :C]
end
refinement_integer = Module.new do
refine Integer do
def bar
"bar is not seen from A methods"
end
end
end
it "looks in the lexical scope refinements before other active refinements" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
refinement_local = Module.new do
refine refined_class do
a = Module.new do
def foo
[:LOCAL] + super
super + 1.bar
end
end
end
a = Module.new do
using refinement_local
refinement = Module.new do
refine refined_class do
include a
end
end
def foo
[:A] + super
Module.new do
using refinement
using refinement_integer
-> {
refined_class.new.foo
}.should raise_error(NameError) { |e| e.name.should == :bar }
end
end
refinement = Module.new do
refine refined_class do
include a
# https://bugs.ruby-lang.org/issues/16977
it "looks in the another active refinement if super called from included modules" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
a = Module.new do
def foo
[:A] + super
end
end
b = Module.new do
def foo
[:B] + super
end
end
refinement_a = Module.new do
refine refined_class do
include a
end
end
refinement_b = Module.new do
refine refined_class do
include b
end
end
result = nil
Module.new do
using refinement_a
using refinement_b
result = refined_class.new.foo
end
result.should == [:B, :A, :C]
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
it "looks in the current active refinement from included modules" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
a = Module.new do
def foo
[:A] + super
end
end
b = Module.new do
def foo
[:B] + super
end
end
refinement = Module.new do
refine refined_class do
def foo
[:LAST] + super
end
end
end
refinement_a_b = Module.new do
refine refined_class do
include a
include b
end
end
result = nil
Module.new do
using refinement
using refinement_a_b
result = refined_class.new.foo
end
result.should == [:B, :A, :LAST, :C]
end
result.should == [:A, :LOCAL, :C]
it "looks in the lexical scope refinements before other active refinements" do
refined_class = ModuleSpecs.build_refined_class(for_super: true)
refinement_local = Module.new do
refine refined_class do
def foo
[:LOCAL] + super
end
end
end
a = Module.new do
using refinement_local
def foo
[:A] + super
end
end
refinement = Module.new do
refine refined_class do
include a
end
end
result = nil
Module.new do
using refinement
result = refined_class.new.foo
end
result.should == [:A, :LOCAL, :C]
end
end
end