Sha256: 342f376be3607e4bf282b298c6e3cb39c8e9926e5d47d41011970a3a1d22e580

Contents?: true

Size: 1.6 KB

Versions: 4

Compression:

Stored size: 1.6 KB

Contents

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

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

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

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

    test "deletes invalid to classes" do
      expect_aliases 'String'=>{'String.to_s'=>'s'}
      create_aliases 'String'=>{'AnotherString.name'=>'n', 'String.to_s'=>'s'}
    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 "deletes invalid to methods" do
      expect_aliases 'String'=>{'Date.civil'=>'c'}
      create_aliases 'String'=>{'Date.civil'=>'c', 'Date.uncivil'=>'uc'}
    end

    test "creates aliases" do
      Kernel.eval %[
        class ::SampleClass
          def self.cap; 'itup'; end
        end
        module ::SampleModule; end
      ]
      create_aliases 'SampleModule'=>{'SampleClass.cap'=>'c', 'Sampleclass.dap'=>'d'}
      obj = Object.new.extend SampleModule
      SampleClass.cap.should == obj.c
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

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