Sha256: 3e40b98d3a4c2dbf025789f7b848204f6f0d7fe71f536734047254af10c56c7b

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe Transproc::ClassTransformations do
  describe '.constructor_inject' do
    let(:klass) do
      Struct.new(:name, :age) { include Equalizer.new(:name, :age) }
    end

    it 'returns a new object initialized with the given arguments' do
      constructor_inject = described_class.t(:constructor_inject, klass)

      input = ['Jane', 25]
      output = klass.new(*input)
      result = constructor_inject[*input]

      expect(result).to eql(output)
      expect(result).to be_instance_of(klass)
    end
  end

  describe '.set_ivars' do
    let(:klass) do
      Class.new do
        include Anima.new(:name, :age)

        attr_reader :test

        def initialize(*args)
          super
          @test = true
        end
      end
    end

    it 'allocates a new object and sets instance variables from hash key/value pairs' do
      set_ivars = described_class.t(:set_ivars, klass)

      input = { name: 'Jane', age: 25 }
      output = klass.new(input)
      result = set_ivars[input]

      expect(result).to eql(output)
      expect(result.test).to be(nil)
      expect(result).to be_instance_of(klass)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
transproc-1.0.3 spec/unit/class_transformations_spec.rb
transproc-1.0.2 spec/unit/class_transformations_spec.rb
transproc-1.0.1 spec/unit/class_transformations_spec.rb
transproc-1.0.0 spec/unit/class_transformations_spec.rb
transproc-0.4.2 spec/unit/class_transformations_spec.rb
transproc-0.4.1 spec/unit/class_transformations_spec.rb
transproc-0.4.0 spec/unit/class_transformations_spec.rb
transproc-0.3.2 spec/unit/class_transformations_spec.rb
transproc-0.3.1 spec/unit/class_transformations_spec.rb
transproc-0.3.0 spec/unit/class_transformations_spec.rb