diff options
author | Jeremy Evans <code@jeremyevans.net> | 2020-03-27 15:08:52 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-04-10 00:29:05 -0700 |
commit | 900e83b50115afda3f79712310e4cb95e4508972 (patch) | |
tree | 07c581a76af2b2e135f034eb52a9e81401e6e131 /spec/ruby/core/exception | |
parent | defc0ee9d172c2caa8742cc682a8aa389942d6ef (diff) |
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]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2987
Diffstat (limited to 'spec/ruby/core/exception')
-rw-r--r-- | spec/ruby/core/exception/name_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/exception/receiver_spec.rb | 6 |
2 files changed, 3 insertions, 7 deletions
diff --git a/spec/ruby/core/exception/name_spec.rb b/spec/ruby/core/exception/name_spec.rb index d1def51f24..c8a49b40e2 100644 --- a/spec/ruby/core/exception/name_spec.rb +++ b/spec/ruby/core/exception/name_spec.rb @@ -21,9 +21,7 @@ describe "NameError#name" do it "returns a class variable name as a symbol" do -> { - -> { - @@doesnt_exist - }.should complain(/class variable access from toplevel/) + eval("class singleton_class::A; @@doesnt_exist end", binding, __FILE__, __LINE__) }.should raise_error(NameError) { |e| e.name.should == :@@doesnt_exist } end diff --git a/spec/ruby/core/exception/receiver_spec.rb b/spec/ruby/core/exception/receiver_spec.rb index 7c57d63c3e..d1c23b67be 100644 --- a/spec/ruby/core/exception/receiver_spec.rb +++ b/spec/ruby/core/exception/receiver_spec.rb @@ -28,10 +28,8 @@ describe "NameError#receiver" do it "returns the Object class when an undefined class variable is called" do -> { - -> { - @@doesnt_exist - }.should complain(/class variable access from toplevel/) - }.should raise_error(NameError) {|e| e.receiver.should equal(Object) } + eval("class singleton_class::A; @@doesnt_exist end", binding, __FILE__, __LINE__) + }.should raise_error(NameError) {|e| e.receiver.should equal(singleton_class::A) } end it "returns a class when an undefined class variable is called in a subclass' namespace" do |