1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2019-07-27 12:40:09 +02:00
parent a06301b103
commit 5c276e1cc9
1247 changed files with 5316 additions and 5028 deletions

View file

@ -49,10 +49,10 @@ describe "Literal (A::X) constant resolution" do
end
it "does not search the singleton class of the class or module" do
lambda do
-> do
ConstantSpecs::ContainerA::ChildA::CS_CONST14
end.should raise_error(NameError)
lambda { ConstantSpecs::CS_CONST14 }.should raise_error(NameError)
-> { ConstantSpecs::CS_CONST14 }.should raise_error(NameError)
end
end
@ -112,7 +112,7 @@ describe "Literal (A::X) constant resolution" do
CS_CONST108 = :const108_1
end
lambda do
-> do
ConstantSpecs::ContainerB::ChildB::CS_CONST108
end.should raise_error(NameError)
@ -122,7 +122,7 @@ describe "Literal (A::X) constant resolution" do
end
end
lambda { ConstantSpecs::CS_CONST108 }.should raise_error(NameError)
-> { ConstantSpecs::CS_CONST108 }.should raise_error(NameError)
end
it "returns the updated value when a constant is reassigned" do
@ -151,7 +151,7 @@ describe "Literal (A::X) constant resolution" do
end
it "raises a NameError if no constant is defined in the search path" do
lambda { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
-> { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
end
it "sends #const_missing to the original class or module scope" do
@ -163,10 +163,10 @@ describe "Literal (A::X) constant resolution" do
end
it "raises a TypeError if a non-class or non-module qualifier is given" do
lambda { CS_CONST1::CS_CONST }.should raise_error(TypeError)
lambda { 1::CS_CONST }.should raise_error(TypeError)
lambda { "mod"::CS_CONST }.should raise_error(TypeError)
lambda { false::CS_CONST }.should raise_error(TypeError)
-> { CS_CONST1::CS_CONST }.should raise_error(TypeError)
-> { 1::CS_CONST }.should raise_error(TypeError)
-> { "mod"::CS_CONST }.should raise_error(TypeError)
-> { false::CS_CONST }.should raise_error(TypeError)
end
end
@ -212,7 +212,7 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of the caller" do
lambda { ConstantSpecs::ClassA.const16 }.should raise_error(NameError)
-> { ConstantSpecs::ClassA.const16 }.should raise_error(NameError)
end
it "searches the lexical scope of a block" do
@ -225,7 +225,7 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of qualifying modules" do
lambda do
-> do
ConstantSpecs::ContainerA::ChildA.const23
end.should raise_error(NameError)
end
@ -302,7 +302,7 @@ describe "Constant resolution within methods" do
it "does not search the lexical scope of the caller" do
ConstantSpecs::ClassB::CS_CONST209 = :const209
lambda { ConstantSpecs::ClassB.const209 }.should raise_error(NameError)
-> { ConstantSpecs::ClassB.const209 }.should raise_error(NameError)
end
it "searches the lexical scope of a block" do
@ -337,14 +337,14 @@ describe "Constant resolution within methods" do
it "does not search the lexical scope of qualifying modules" do
ConstantSpecs::ContainerB::CS_CONST214 = :const214
lambda do
-> do
ConstantSpecs::ContainerB::ChildB.const214
end.should raise_error(NameError)
end
end
it "raises a NameError if no constant is defined in the search path" do
lambda { ConstantSpecs::ParentA.constx }.should raise_error(NameError)
-> { ConstantSpecs::ParentA.constx }.should raise_error(NameError)
end
it "sends #const_missing to the original class or module scope" do
@ -427,7 +427,7 @@ describe "top-level constant lookup" do
context "on a class" do
ruby_version_is "" ... "2.5" do
it "searches Object successfully after searching other scopes" do
->() {
-> {
String::Hash.should == Hash
}.should complain(/toplevel constant Hash referenced by/)
end
@ -435,13 +435,13 @@ describe "top-level constant lookup" do
ruby_version_is "2.5" do
it "does not search Object after searching other scopes" do
->() { String::Hash }.should raise_error(NameError)
-> { String::Hash }.should raise_error(NameError)
end
end
end
it "searches Object unsuccessfully when searches on a module" do
->() { Enumerable::Hash }.should raise_error(NameError)
-> { Enumerable::Hash }.should raise_error(NameError)
end
end
@ -455,7 +455,7 @@ describe "Module#private_constant marked constants" do
mod.const_set :Foo, false
}.should complain(/already initialized constant/)
lambda {mod::Foo}.should raise_error(NameError)
-> {mod::Foo}.should raise_error(NameError)
end
ruby_version_is "2.6" do
@ -473,19 +473,19 @@ describe "Module#private_constant marked constants" do
describe "in a module" do
it "cannot be accessed from outside the module" do
lambda do
-> do
ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
end.should raise_error(NameError)
end
it "cannot be reopened as a module from scope where constant would be private" do
lambda do
-> do
module ConstantVisibility::ModuleContainer::PrivateModule; end
end.should raise_error(NameError)
end
it "cannot be reopened as a class from scope where constant would be private" do
lambda do
-> do
class ConstantVisibility::ModuleContainer::PrivateClass; end
end.should raise_error(NameError)
end
@ -541,19 +541,19 @@ describe "Module#private_constant marked constants" do
describe "in a class" do
it "cannot be accessed from outside the class" do
lambda do
-> do
ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
end.should raise_error(NameError)
end
it "cannot be reopened as a module" do
lambda do
-> do
module ConstantVisibility::ClassContainer::PrivateModule; end
end.should raise_error(NameError)
end
it "cannot be reopened as a class" do
lambda do
-> do
class ConstantVisibility::ClassContainer::PrivateClass; end
end.should raise_error(NameError)
end
@ -609,7 +609,7 @@ describe "Module#private_constant marked constants" do
describe "in Object" do
it "cannot be accessed using ::Const form" do
lambda do
-> do
::PRIVATE_CONSTANT_IN_OBJECT
end.should raise_error(NameError)
end
@ -629,14 +629,14 @@ describe "Module#private_constant marked constants" do
describe "NameError by #private_constant" do
it "has :receiver and :name attributes" do
lambda do
-> do
ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
end.should raise_error(NameError) {|e|
e.receiver.should == ConstantVisibility::PrivConstClass
e.name.should == :PRIVATE_CONSTANT_CLASS
}
lambda do
-> do
ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
end.should raise_error(NameError) {|e|
e.receiver.should == ConstantVisibility::PrivConstModule
@ -645,14 +645,14 @@ describe "Module#private_constant marked constants" do
end
it "has the defined class as the :name attribute" do
lambda do
-> do
ConstantVisibility::PrivConstClassChild::PRIVATE_CONSTANT_CLASS
end.should raise_error(NameError) {|e|
e.receiver.should == ConstantVisibility::PrivConstClass
e.name.should == :PRIVATE_CONSTANT_CLASS
}
lambda do
-> do
ConstantVisibility::PrivConstModuleChild::PRIVATE_CONSTANT_MODULE
end.should raise_error(NameError) {|e|
e.receiver.should == ConstantVisibility::PrivConstModule