mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@21a48d9
This commit is contained in:
parent
3bf36979d8
commit
c75df796d8
25 changed files with 454 additions and 38 deletions
|
@ -82,3 +82,29 @@ describe 'A class variable definition' do
|
|||
c.class_variable_get(:@@cv).should == :next
|
||||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.0" do
|
||||
describe 'Accessing a class variable' do
|
||||
it "raises a RuntimeError when accessed from the toplevel scope (not in some module or class)" do
|
||||
-> {
|
||||
eval "@@cvar_toplevel1"
|
||||
}.should raise_error(RuntimeError, 'class variable access from toplevel')
|
||||
-> {
|
||||
eval "@@cvar_toplevel2 = 2"
|
||||
}.should raise_error(RuntimeError, 'class variable access from toplevel')
|
||||
end
|
||||
|
||||
it "raises a RuntimeError when a class variable is overtaken in an ancestor class" do
|
||||
parent = Class.new()
|
||||
subclass = Class.new(parent)
|
||||
subclass.class_variable_set(:@@cvar_overtaken, :subclass)
|
||||
parent.class_variable_set(:@@cvar_overtaken, :parent)
|
||||
|
||||
-> {
|
||||
subclass.class_variable_get(:@@cvar_overtaken)
|
||||
}.should raise_error(RuntimeError, /class variable @@cvar_overtaken of .+ is overtaken by .+/)
|
||||
|
||||
parent.class_variable_get(:@@cvar_overtaken).should == :parent
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue