Sha256: d5e3f1336fd99cc5d6467f05b436ed62bb50e66dad744cca32ec08f99e0c9c4d

Contents?: true

Size: 1.12 KB

Versions: 24

Compression:

Stored size: 1.12 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'
require 'mspec/helpers/const_lookup'

CONST = 2

module ConstLookupSpecs
  class A
    class B
      CONST = 1
    end

    class C; end

    class D
      def self.const_missing(const)
        A::B::CONST
      end
    end
  end
end

describe Kernel, "#const_lookup" do
  it "returns the constant specified by 'A::B'" do
    const_lookup("ConstLookupSpecs::A::B").should == ConstLookupSpecs::A::B
  end

  it "returns a regular constant specified without scoping" do
    const_lookup("ConstLookupSpecs").should == ConstLookupSpecs
  end

  it "returns an explicit toplevel constant" do
    const_lookup("::ConstLookupSpecs").should == ConstLookupSpecs
  end

  it "returns the constant from the proper scope" do
    const_lookup("ConstLookupSpecs::A::B::CONST").should == 1
  end

  it "raises NameError if the constant is not contained within the module's scope" do
    lambda {
      const_lookup("ConstLookupSpecs::A::C::CONST")
    }.should raise_error(NameError)
  end

  it "returns the value of #const_missing" do
    const_lookup("ConstLookupSpecs::A::D::CONST").should == 1
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
mspec-1.5.17 spec/helpers/const_lookup_spec.rb
mspec-1.5.16 spec/helpers/const_lookup_spec.rb
mspec-1.5.15 spec/helpers/const_lookup_spec.rb
mspec-1.5.14 spec/helpers/const_lookup_spec.rb
mspec-1.5.13 spec/helpers/const_lookup_spec.rb
mspec-1.5.11 spec/helpers/const_lookup_spec.rb
mspec-1.5.12 spec/helpers/const_lookup_spec.rb
mspec-1.5.3 spec/helpers/const_lookup_spec.rb
mspec-1.1.1 spec/helpers/const_lookup_spec.rb
mspec-1.3.0 spec/helpers/const_lookup_spec.rb
mspec-1.3.1 spec/helpers/const_lookup_spec.rb
mspec-1.4.0 spec/helpers/const_lookup_spec.rb
mspec-1.5.1 spec/helpers/const_lookup_spec.rb
mspec-1.1.0 spec/helpers/const_lookup_spec.rb
mspec-1.2.0 spec/helpers/const_lookup_spec.rb
mspec-1.5.0 spec/helpers/const_lookup_spec.rb
mspec-1.5.10 spec/helpers/const_lookup_spec.rb
mspec-1.5.2 spec/helpers/const_lookup_spec.rb
mspec-1.5.4 spec/helpers/const_lookup_spec.rb
mspec-1.5.8 spec/helpers/const_lookup_spec.rb