Sha256: 32322ac29703b31ccbf2b0ee4d163495f1fc15f9695486a0eef81832e0152de3

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

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

class Alias::Creators::ClassMethodCreatorTest < Test::Unit::TestCase
  
  context "ClassMethodCreator" do
    before(:each) { @manager = Alias::Manager.new }
    def expect_aliases(hash)
      arr = Alias::Creators::ClassMethodCreator.maps_config(hash)
      Alias::Creators::ClassMethodCreator.expects(:generates_aliases).with(arr).returns('')
    end

    def create_aliases(hash)
      @manager.create_aliases(:class_method, hash)
    end
    
    test "deletes invalid class method keys" do
      expect_aliases "Array"=>{}, "String"=>{'yaml_new'=>'yn'}
      create_aliases 'String'=>{'yaml_new'=>'yn'},'Array'=>{'blah'=>'bl'}
    end
  
    test "deletes invalid classes" do
      expect_aliases "String"=>{'yaml_new'=>'yn'}
      create_aliases 'String'=>{'yaml_new'=>'yn'},'Blah'=>{'new'=>'n'}
    end

    test "deletes existing class method aliases" do
      expect_aliases 'Date'=>{'valid_time?'=>'vt'}
      create_aliases 'Date'=>{'civil_to_jd'=>'civil', 'valid_time?'=>'vt'}
    end

    test "creates class method aliases" do
      Kernel.eval %[
        class ::SampleClass
          def self.cap; 'itup'; end
        end
      ]
      hash1 = {'SampleClass'=>{:cap=>:capohow}, 'Array'=>{:blah=>:bl}}
      @manager.create_aliases(:class_method, hash1)
      SampleClass.capohow.should == SampleClass.cap
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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