Sha256: 7cb2c141ab4feeff6b3e4c1e633e3b5f441cea02994d5519c84a4547cba595b9

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

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

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

    def expect_aliases(hash)
      arr = Alias::Creators::AnyToInstanceMethodCreator.maps_config(hash)
      Alias::Creators::AnyToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
    end

    def create_aliases(hash)
      @manager.create_aliases(:any_to_instance_method, hash)
    end

    test "deletes invalid classes" do
      expect_aliases 'String'=>{'String.to_s'=>'s'}
      create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
    end

    test "deletes existing method aliases" do
      expect_aliases 'String'=>{'Date.commercial'=>'s'}
      create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
    end

    test "creates aliases" do
      Kernel.eval %[
        class ::SomeClass
          def self.cap; 'itup'; end
        end
        module ::SomeModule; end
      ]
      create_aliases 'SomeModule'=>{'SomeClass.cap.to_sym'=>'c', 'SomeClass.cap.gsub'=>'gsub'}
      obj = Object.new.extend SomeModule
      SomeClass.cap.to_sym.should == obj.c
      SomeClass.cap.gsub('cap','smack') == obj.gsub('cap','smack')
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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