Sha256: 2d9c3859e527044e606d2a3c3bf89be3ba4e033c18d42ed09644e807b17c3e14

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

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

describe "AnyToInstanceMethodCreator" do
  before { @manager = Manager.new }

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

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

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

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

  it "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').should == obj.gsub('cap','smack')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alias-0.2.3 test/any_to_instance_method_creator_test.rb
alias-0.2.2 test/any_to_instance_method_creator_test.rb