diff options
Diffstat (limited to 'spec/ruby/language/constants_spec.rb')
| -rw-r--r-- | spec/ruby/language/constants_spec.rb | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb index 063c52c422..0880230a36 100644 --- a/spec/ruby/language/constants_spec.rb +++ b/spec/ruby/language/constants_spec.rb @@ -51,8 +51,8 @@ describe "Literal (A::X) constant resolution" do it "does not search the singleton class of the class or module" do -> do ConstantSpecs::ContainerA::ChildA::CS_CONST14 - end.should raise_error(NameError) - -> { ConstantSpecs::CS_CONST14 }.should raise_error(NameError) + end.should.raise(NameError) + -> { ConstantSpecs::CS_CONST14 }.should.raise(NameError) end end @@ -135,7 +135,7 @@ describe "Literal (A::X) constant resolution" do -> do ConstantSpecs::ContainerB::ChildB::CS_CONST108 - end.should raise_error(NameError) + end.should.raise(NameError) module ConstantSpecs class << self @@ -143,7 +143,7 @@ describe "Literal (A::X) constant resolution" do end end - -> { ConstantSpecs::CS_CONST108 }.should raise_error(NameError) + -> { ConstantSpecs::CS_CONST108 }.should.raise(NameError) ensure ConstantSpecs::ContainerB::ChildB.singleton_class.send(:remove_const, :CS_CONST108) ConstantSpecs.singleton_class.send(:remove_const, :CS_CONST108) @@ -175,7 +175,7 @@ describe "Literal (A::X) constant resolution" do end it "raises a NameError if no constant is defined in the search path" do - -> { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError) + -> { ConstantSpecs::ParentA::CS_CONSTX }.should.raise(NameError) end it "uses the module or class #name to craft the error message" do @@ -189,7 +189,7 @@ describe "Literal (A::X) constant resolution" do end end - -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/) + -> { mod::DOES_NOT_EXIST }.should.raise(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/) end it "uses the module or class #inspect to craft the error message if they are anonymous" do @@ -203,7 +203,7 @@ describe "Literal (A::X) constant resolution" do end end - -> { mod::DOES_NOT_EXIST }.should raise_error(NameError, /uninitialized constant <unusable info>::DOES_NOT_EXIST/) + -> { mod::DOES_NOT_EXIST }.should.raise(NameError, /uninitialized constant <unusable info>::DOES_NOT_EXIST/) end it "sends #const_missing to the original class or module scope" do @@ -215,10 +215,10 @@ describe "Literal (A::X) constant resolution" do end it "raises a TypeError if a non-class or non-module qualifier is given" do - -> { 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) + -> { CS_CONST1::CS_CONST }.should.raise(TypeError) + -> { 1::CS_CONST }.should.raise(TypeError) + -> { "mod"::CS_CONST }.should.raise(TypeError) + -> { false::CS_CONST }.should.raise(TypeError) end end @@ -264,7 +264,7 @@ describe "Constant resolution within methods" do end it "does not search the lexical scope of the caller" do - -> { ConstantSpecs::ClassA.const16 }.should raise_error(NameError) + -> { ConstantSpecs::ClassA.const16 }.should.raise(NameError) end it "searches the lexical scope of a block" do @@ -279,7 +279,7 @@ describe "Constant resolution within methods" do it "does not search the lexical scope of qualifying modules" do -> do ConstantSpecs::ContainerA::ChildA.const23 - end.should raise_error(NameError) + end.should.raise(NameError) end end @@ -377,7 +377,7 @@ describe "Constant resolution within methods" do it "does not search the lexical scope of the caller" do ConstantSpecs::ClassB::CS_CONST209 = :const209 - -> { ConstantSpecs::ClassB.const209 }.should raise_error(NameError) + -> { ConstantSpecs::ClassB.const209 }.should.raise(NameError) ensure ConstantSpecs::ClassB.send(:remove_const, :CS_CONST209) end @@ -426,14 +426,14 @@ describe "Constant resolution within methods" do -> do ConstantSpecs::ContainerB::ChildB.const214 - end.should raise_error(NameError) + end.should.raise(NameError) ensure ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST214) end end it "raises a NameError if no constant is defined in the search path" do - -> { ConstantSpecs::ParentA.constx }.should raise_error(NameError) + -> { ConstantSpecs::ParentA.constx }.should.raise(NameError) end it "sends #const_missing to the original class or module scope" do @@ -456,7 +456,7 @@ describe "Constant resolution within a singleton class (class << obj)" do it "uses its own namespace for nested modules" do a = ConstantSpecs::CS_SINGLETON3[0].x b = ConstantSpecs::CS_SINGLETON3[1].x - a.should_not equal(b) + a.should_not.equal?(b) end it "allows nested modules to have proper resolution" do @@ -469,12 +469,12 @@ end describe "top-level constant lookup" do context "on a class" do it "does not search Object after searching other scopes" do - -> { String::Hash }.should raise_error(NameError) + -> { String::Hash }.should.raise(NameError) end end it "searches Object unsuccessfully when searches on a module" do - -> { Enumerable::Hash }.should raise_error(NameError) + -> { Enumerable::Hash }.should.raise(NameError) end end @@ -488,7 +488,7 @@ describe "Module#private_constant marked constants" do mod.const_set :Foo, false }.should complain(/already initialized constant/) - -> {mod::Foo}.should raise_error(NameError) + -> {mod::Foo}.should.raise(NameError) end it "sends #const_missing to the original class or module" do @@ -506,19 +506,19 @@ describe "Module#private_constant marked constants" do it "cannot be accessed from outside the module" do -> do ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE - end.should raise_error(NameError) + end.should.raise(NameError) end it "cannot be reopened as a module from scope where constant would be private" do -> do module ConstantVisibility::ModuleContainer::PrivateModule; end - end.should raise_error(NameError) + end.should.raise(NameError) end it "cannot be reopened as a class from scope where constant would be private" do -> do class ConstantVisibility::ModuleContainer::PrivateClass; end - end.should raise_error(NameError) + end.should.raise(NameError) end it "can be reopened as a module where constant is not private" do @@ -554,7 +554,7 @@ describe "Module#private_constant marked constants" do end it "can be accessed from the module itself" do - ConstantVisibility::PrivConstModule.private_constant_from_self.should be_true + ConstantVisibility::PrivConstModule.private_constant_from_self.should == true end it "is defined? from the module itself" do @@ -562,7 +562,7 @@ describe "Module#private_constant marked constants" do end it "can be accessed from lexical scope" do - ConstantVisibility::PrivConstModule::Nested.private_constant_from_scope.should be_true + ConstantVisibility::PrivConstModule::Nested.private_constant_from_scope.should == true end it "is defined? from lexical scope" do @@ -570,20 +570,20 @@ describe "Module#private_constant marked constants" do end it "can be accessed from classes that include the module" do - ConstantVisibility::ClassIncludingPrivConstModule.new.private_constant_from_include.should be_true + ConstantVisibility::ClassIncludingPrivConstModule.new.private_constant_from_include.should == true end it "can be accessed from modules that include the module" do - ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_from_include.should be_true + ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_from_include.should == true end it "raises a NameError when accessed directly from modules that include the module" do -> do ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_self_from_include - end.should raise_error(NameError) + end.should.raise(NameError) -> do ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_named_from_include - end.should raise_error(NameError) + end.should.raise(NameError) end it "is defined? from classes that include the module" do @@ -595,19 +595,19 @@ describe "Module#private_constant marked constants" do it "cannot be accessed from outside the class" do -> do ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS - end.should raise_error(NameError) + end.should.raise(NameError) end it "cannot be reopened as a module" do -> do module ConstantVisibility::ClassContainer::PrivateModule; end - end.should raise_error(NameError) + end.should.raise(NameError) end it "cannot be reopened as a class" do -> do class ConstantVisibility::ClassContainer::PrivateClass; end - end.should raise_error(NameError) + end.should.raise(NameError) end it "can be reopened as a module where constant is not private" do @@ -643,7 +643,7 @@ describe "Module#private_constant marked constants" do end it "can be accessed from the class itself" do - ConstantVisibility::PrivConstClass.private_constant_from_self.should be_true + ConstantVisibility::PrivConstClass.private_constant_from_self.should == true end it "is defined? from the class itself" do @@ -651,7 +651,7 @@ describe "Module#private_constant marked constants" do end it "can be accessed from lexical scope" do - ConstantVisibility::PrivConstClass::Nested.private_constant_from_scope.should be_true + ConstantVisibility::PrivConstClass::Nested.private_constant_from_scope.should == true end it "is defined? from lexical scope" do @@ -659,7 +659,7 @@ describe "Module#private_constant marked constants" do end it "can be accessed from subclasses" do - ConstantVisibility::PrivConstClassChild.new.private_constant_from_subclass.should be_true + ConstantVisibility::PrivConstClassChild.new.private_constant_from_subclass.should == true end it "is defined? from subclasses" do @@ -671,7 +671,7 @@ describe "Module#private_constant marked constants" do it "cannot be accessed using ::Const form" do -> do ::PRIVATE_CONSTANT_IN_OBJECT - end.should raise_error(NameError) + end.should.raise(NameError) end it "is not defined? using ::Const form" do @@ -691,14 +691,14 @@ describe "Module#private_constant marked constants" do it "has :receiver and :name attributes" do -> do ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS - end.should raise_error(NameError) {|e| + end.should.raise(NameError) {|e| e.receiver.should == ConstantVisibility::PrivConstClass e.name.should == :PRIVATE_CONSTANT_CLASS } -> do ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE - end.should raise_error(NameError) {|e| + end.should.raise(NameError) {|e| e.receiver.should == ConstantVisibility::PrivConstModule e.name.should == :PRIVATE_CONSTANT_MODULE } @@ -707,14 +707,14 @@ describe "Module#private_constant marked constants" do it "has the defined class as the :name attribute" do -> do ConstantVisibility::PrivConstClassChild::PRIVATE_CONSTANT_CLASS - end.should raise_error(NameError) {|e| + end.should.raise(NameError) {|e| e.receiver.should == ConstantVisibility::PrivConstClass e.name.should == :PRIVATE_CONSTANT_CLASS } -> do ConstantVisibility::ClassIncludingPrivConstModule::PRIVATE_CONSTANT_MODULE - end.should raise_error(NameError) {|e| + end.should.raise(NameError) {|e| e.receiver.should == ConstantVisibility::PrivConstModule e.name.should == :PRIVATE_CONSTANT_MODULE } @@ -783,7 +783,7 @@ describe 'Allowed characters' do it 'does not allow not ASCII characters that cannot be upcased or lowercased at the beginning' do -> do Module.new.const_set("થBB", 1) - end.should raise_error(NameError, /wrong constant name/) + end.should.raise(NameError, /wrong constant name/) end it 'allows not ASCII upcased characters at the beginning' do @@ -803,7 +803,7 @@ describe 'Assignment' do B = 1 end CODE - end.should raise_error(SyntaxError, /dynamic constant assignment/) + end.should.raise(SyntaxError, /dynamic constant assignment/) end end end |
