mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Turn class variable warnings into exceptions
This changes the following warnings: * warning: class variable access from toplevel * warning: class variable @foo of D is overtaken by C into RuntimeErrors. Handle defined?(@@foo) at toplevel by returning nil instead of raising an exception (the previous behavior warned before returning nil when defined? was used). Refactor the specs to avoid the warnings even in older versions. The specs were checking for the warnings, but the purpose of the related specs as evidenced from their description is to test for behavior, not for warnings. Fixes [Bug #14541]
This commit is contained in:
parent
defc0ee9d1
commit
900e83b501
Notes:
git
2020-04-10 16:29:30 +09:00
9 changed files with 37 additions and 34 deletions
|
@ -275,9 +275,7 @@ describe "The defined? keyword for an expression" do
|
|||
end
|
||||
|
||||
it "returns nil for an expression with '!' and an unset class variable" do
|
||||
-> {
|
||||
@result = defined?(!@@defined_specs_undefined_class_variable)
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
@result = eval("class singleton_class::A; defined?(!@@doesnt_exist) end", binding, __FILE__, __LINE__)
|
||||
@result.should be_nil
|
||||
end
|
||||
|
||||
|
@ -286,9 +284,7 @@ describe "The defined? keyword for an expression" do
|
|||
end
|
||||
|
||||
it "returns nil for an expression with 'not' and an unset class variable" do
|
||||
-> {
|
||||
@result = defined?(not @@defined_specs_undefined_class_variable)
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
@result = eval("class singleton_class::A; defined?(not @@doesnt_exist) end", binding, __FILE__, __LINE__)
|
||||
@result.should be_nil
|
||||
end
|
||||
|
||||
|
@ -897,17 +893,21 @@ describe "The defined? keyword for a variable scoped constant" do
|
|||
end
|
||||
|
||||
it "returns nil if the class scoped constant is not defined" do
|
||||
-> {
|
||||
@@defined_specs_obj = DefinedSpecs::Basic
|
||||
defined?(@@defined_specs_obj::Undefined).should be_nil
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
eval(<<-END, binding, __FILE__, __LINE__)
|
||||
class singleton_class::A
|
||||
@@defined_specs_obj = DefinedSpecs::Basic
|
||||
defined?(@@defined_specs_obj::Undefined).should be_nil
|
||||
end
|
||||
END
|
||||
end
|
||||
|
||||
it "returns 'constant' if the constant is defined in the scope of the class variable" do
|
||||
-> {
|
||||
@@defined_specs_obj = DefinedSpecs::Basic
|
||||
defined?(@@defined_specs_obj::A).should == "constant"
|
||||
}.should complain(/class variable access from toplevel/)
|
||||
eval(<<-END, binding, __FILE__, __LINE__)
|
||||
class singleton_class::A
|
||||
@@defined_specs_obj = DefinedSpecs::Basic
|
||||
defined?(@@defined_specs_obj::A).should == "constant"
|
||||
end
|
||||
END
|
||||
end
|
||||
|
||||
it "returns nil if the local scoped constant is not defined" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue