Sha256: a11c187af3a7b8a838c4f9c98bc72d109fb3979f07b54a9847a584a1a0bdcc06

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

require File.join(File.dirname(__FILE__), 'test_helper.rb')

class Alias::Creators::ConstantCreatorTest < Test::Unit::TestCase
  context "AliasConstantCreator" do
    before(:each) { @manager = Alias::Manager.new }

    def create_aliases(hash, options={})
      @manager.create_aliases(:constant, hash, options)
    end

    def expect_aliases(hash)
      arr = Alias::Creators::ConstantCreator.maps_config(hash)
      Alias::Creators::ConstantCreator.expects(:generates_aliases).with(arr).returns('')
    end
    
    test "deletes existing aliases" do
      expect_aliases "Array"=>'Ar'
      create_aliases "Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"
    end

    test "deletes existing aliases unless force option" do
      h1 = {"Alias::Creators::ConstantCreator"=>"Alias::Creator", "Array"=>"Ar"}
      expect_aliases h1
      create_aliases h1, :force=>true
    end

    test "deletes invalid classes" do
      eval "module ::Bling; end"
      expect_aliases 'Array'=>'Ar'
      create_aliases "Blah"=>"Bling", "Array"=>"Ar"
    end

    test "creates aliases" do
      create_aliases 'Time'=>'T'
      ::Time.should == ::T
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
cldwalker-alias-0.2.0 test/constant_creator_test.rb
cldwalker-alias-0.2.1 test/constant_creator_test.rb
alias-0.2.0 test/constant_creator_test.rb
alias-0.2.1 test/constant_creator_test.rb