Sha256: d5867818d933d92ace074c3aca96ef381099c5e0bb3030c577afced915e8d848

Contents?: true

Size: 1.82 KB

Versions: 22

Compression:

Stored size: 1.82 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe Module do

  before(:all) do
    module ::Foo
      module ModBar
        module Noo
          module Too
            module Boo
            end
          end
        end
      end

      class Zed
      end
    end

    class ::Baz
    end

    class ::Bar
    end
  end

  it "should raise NameError for a missing constant" do
    lambda { Foo.find_const('Moo') }.should raise_error(NameError)
    lambda { Object.find_const('MissingConstant') }.should raise_error(NameError)
  end

  it "should be able to get a recursive constant" do
    Object.find_const('Foo::ModBar').should == Foo::ModBar
  end

  it "should ignore get Constants from the Kernel namespace correctly" do
    Object.find_const('::Foo::ModBar').should == ::Foo::ModBar
  end

  it "should find relative constants" do
    Foo.find_const('ModBar').should == Foo::ModBar
    Foo.find_const('Baz').should == Baz
  end

  it "should find sibling constants" do
    Foo::ModBar.find_const("Zed").should == Foo::Zed
  end

  it "should find nested constants on nested constants" do
    Foo::ModBar.find_const('Noo::Too').should == Foo::ModBar::Noo::Too
  end

  it "should find constants outside of nested constants" do
    Foo::ModBar::Noo::Too.find_const("Zed").should == Foo::Zed
  end

  it 'should be able to find past the second nested level' do
    Foo::ModBar::Noo.find_const('Too').should == Foo::ModBar::Noo::Too
    Foo::ModBar::Noo::Too.find_const('Boo').should == Foo::ModBar::Noo::Too::Boo
  end


  it "should be able to deal with constants being added and removed" do
    Object.find_const('Bar') # First we load Bar with find_const
    Object.module_eval { remove_const('Bar') } # Now we delete it
    module ::Bar; end; # Now we redefine it
    Object.find_const('Bar').should == Bar
  end

end

Version data entries

22 entries across 21 versions & 5 rubygems

Version Path
sundbp-extlib-0.9.14 spec/module_spec.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.8/gems/extlib-0.9.14/spec/module_spec.rb
middleman-0.13.1 lib/middleman/vendor/gems/ruby/1.9.1/gems/extlib-0.9.14/spec/module_spec.rb
middleman-0.12.2 lib/middleman/vendor/gems/gems/extlib-0.9.14/spec/module_spec.rb
middleman-0.12.1 lib/middleman/vendor/gems/gems/extlib-0.9.14/spec/module_spec.rb
extlib-0.9.14 spec/module_spec.rb
ginst-2009.12.8 vendor/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.12.0.pre3 lib/middleman/vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.12.0.pre2 lib/middleman/vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.12.0.pre lib/middleman/vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
ginst-2009.11.24 vendor/gems/extlib-0.9.13/spec/module_spec.rb
ginst-2009.11.23 vendor/gems/extlib-0.9.13/spec/module_spec.rb
rango-0.0.6 vendor/extlib/spec/module_spec.rb
rango-0.1.pre vendor/extlib/spec/module_spec.rb
middleman-0.10.17 vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.10.16 vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.10.15 vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
middleman-0.10.14 vendor/gems/gems/extlib-0.9.13/spec/module_spec.rb
ginst-2.0.1 vendor/gems/extlib-0.9.13/spec/module_spec.rb
ginst-2.0.0 vendor/gems/extlib-0.9.13/spec/module_spec.rb