Sha256: cc764c557df6655d8ad2e2c25620a608e7c674f5bbf7c1c7aed19d894fcf8d59

Contents?: true

Size: 1.36 KB

Versions: 49

Compression:

Stored size: 1.36 KB

Contents

module ConstantsSpecsModule
  MOD_CONST1 = "1"
  MOD_CONST2 = "2"
  MOD_CONST3 = "3"

  module Foo
    FOO = "foo"
  end
end

class ConstantsSpecsClass
  CLASS_CONST1 = "1"
  CLASS_CONST2 = "2"
  CLASS_CONST3 = "3"
end

class SubConstantsSpecsClass < ConstantsSpecsClass
  CLASS_CONST4 = "4"
end

describe "Module#constants" do
  it "should return constants in global scope when called from Module or Class" do
    result = Module.constants
    result.should include("Module", "Object", "TrueClass", "FalseClass", "RUBY_ENGINE")
    result2 = Class.constants
    result.should == result2
  end

  it "should only return constants and child modules defined directly on module" do
    result = ConstantsSpecsModule.constants
    result.size.should == 4
    result.should include("MOD_CONST1", "MOD_CONST2", "MOD_CONST3", "Foo")
    result = ConstantsSpecsModule::Foo.constants
    result.size.should == 1
    result.should include("FOO")
  end

  it "should only return constants defined directly on class" do
    result = ConstantsSpecsClass.constants
    result.size.should == 3
    result.should include("CLASS_CONST1", "CLASS_CONST2", "CLASS_CONST3")
  end

  it "should include constants inherited from superclass" do
    result = SubConstantsSpecsClass.constants
    result.size.should == 4
    result.should include("CLASS_CONST4", "CLASS_CONST1", "CLASS_CONST2", "CLASS_CONST3")
  end
end

Version data entries

49 entries across 49 versions & 3 rubygems

Version Path
opal-0.10.6 spec/opal/core/module/constants_spec.rb
opal-0.10.6.beta spec/opal/core/module/constants_spec.rb
opal-0.10.5 spec/opal/core/module/constants_spec.rb
opal-0.10.4 spec/opal/core/module/constants_spec.rb
opal-0.11.0.rc1 spec/opal/core/module/constants_spec.rb
opal-0.10.3 spec/opal/core/module/constants_spec.rb
opal-0.10.2 spec/opal/core/module/constants_spec.rb
opal-0.10.1 spec/opal/core/module/constants_spec.rb
opal-0.10.0 spec/opal/core/module/constants_spec.rb
opal-0.10.0.rc2 spec/opal/core/module/constants_spec.rb
opal-0.9.4 spec/opal/core/module/constants_spec.rb
opal-0.9.3 spec/opal/core/module/constants_spec.rb
opal-0.10.0.rc1 spec/opal/core/module/constants_spec.rb
opal-0.10.0.beta5 spec/opal/core/module/constants_spec.rb
opal-0.10.0.beta4 spec/opal/core/module/constants_spec.rb
opal-0.10.0.beta3 spec/opal/core/module/constants_spec.rb
opal-0.10.0.beta2 spec/opal/core/module/constants_spec.rb
opal-0.10.0.beta1 spec/opal/core/module/constants_spec.rb
opal-0.9.2 spec/opal/core/module/constants_spec.rb
opal-0.9.0 spec/opal/core/module/constants_spec.rb