diff options
Diffstat (limited to 'spec/ruby/core/module/constants_spec.rb')
| -rw-r--r-- | spec/ruby/core/module/constants_spec.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/spec/ruby/core/module/constants_spec.rb b/spec/ruby/core/module/constants_spec.rb index 4538e828dd..f2f12761e3 100644 --- a/spec/ruby/core/module/constants_spec.rb +++ b/spec/ruby/core/module/constants_spec.rb @@ -13,12 +13,13 @@ describe "Module.constants" do it "returns an array of Symbol names" do # This in NOT an exhaustive list - Module.constants.should include(:Array, :Bignum, :Class, :Comparable, :Dir, + Module.constants.to_set.should >= Set[ + :Array, :Class, :Comparable, :Dir, :Enumerable, :ENV, :Exception, :FalseClass, - :File, :Fixnum, :Float, :Hash, :Integer, :IO, + :File, :Float, :Hash, :Integer, :IO, :Kernel, :Math, :Method, :Module, :NilClass, :Numeric, :Object, :Range, :Regexp, :String, - :Symbol, :Thread, :Time, :TrueClass) + :Symbol, :Thread, :Time, :TrueClass] end it "returns Module's constants when given a parameter" do @@ -43,37 +44,43 @@ end describe "Module#constants" do it "returns an array of Symbol names of all constants defined in the module and all included modules" do ConstantSpecs::ContainerA.constants.sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA ] end it "returns all constants including inherited when passed true" do ConstantSpecs::ContainerA.constants(true).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA ] end it "returns all constants including inherited when passed some object" do ConstantSpecs::ContainerA.constants(Object.new).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA + :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA ] end it "doesn't returns inherited constants when passed false" do ConstantSpecs::ContainerA.constants(false).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA + :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST5, :ChildA ] end it "doesn't returns inherited constants when passed nil" do ConstantSpecs::ContainerA.constants(nil).sort.should == [ - :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA + :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST5, :ChildA ] end it "returns only public constants" do ModuleSpecs::PrivConstModule.constants.should == [:PUBLIC_CONSTANT] end + + it "returns only constants starting with an uppercase letter" do + # e.g. fatal, IO::generic_readable and IO::generic_writable should not be returned by Module#constants + Object.constants.each { |c| c[0].should == c[0].upcase } + IO.constants.each { |c| c[0].should == c[0].upcase } + end end describe "Module#constants" do @@ -86,6 +93,6 @@ describe "Module#constants" do end it "includes names of constants defined after a module is included" do - ConstantSpecs::ContainerA.constants.should include(:CS_CONST251) + ConstantSpecs::ContainerA.constants.should.include?(:CS_CONST251) end end |
