Sha256: c05e5c2cdc1147a46defdc9d24db75501c7de29cb284fd3826ac7e9f8bc3b2ff

Contents?: true

Size: 919 Bytes

Versions: 4

Compression:

Stored size: 919 Bytes

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../../fixtures/constants', __FILE__)

CS_CONST1 = :const1

module ConstGetSpecs
  FOO = 100
  
  module Bar
    BAR = 200

    module Baz
      BAZ = 300
    end
  end
end

describe "Module#const_get" do
  it "accepts a String or Symbol name" do
    Object.const_get(:CS_CONST1).should == :const1
    Object.const_get("CS_CONST1").should == :const1
  end

  it "raises a NameError if no constant is defined in the search path" do
    lambda { Object.const_get :CS_CONSTX_BAD }.should raise_error(NameError)
  end

  it "searches parent scopes of classes and modules" do
    ConstGetSpecs::Bar::Baz.const_get(:BAZ).should eq(300)
    ConstGetSpecs::Bar::Baz.const_get(:BAR).should eq(200)
    ConstGetSpecs::Bar::Baz.const_get(:FOO).should eq(100)
    ConstGetSpecs::Bar::Baz.const_get(:Bar).should eq(ConstGetSpecs::Bar)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/module/const_get_spec.rb
opal-0.3.40 spec/core/module/const_get_spec.rb
opal-0.3.39 spec/core/module/const_get_spec.rb
opal-0.3.38 spec/core/module/const_get_spec.rb