Sha256: accf51ba36f497aaa39816d92b7d48de4466d0455b4a850e34567682960d654a

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

require_relative 'remi_spec'

describe Transform do

  context 'a transform with a single argument' do
    before do
      class SingleArgument < Transform
        def initialize(*args, **kargs, &block)
          super
        end

        def transform(value)
          value
        end
      end
    end

    let(:transform) { SingleArgument.new }

    it 'can be converted into a proc and called' do
      expect(transform.to_proc.call(5)).to eq 5
    end

    it 'can be called directly' do
      expect(transform.call(5)).to eq 5
    end
  end

  context 'a transform that accepts multiple arguments' do
    before do
      class MultipleArgument < Transform
        def initialize(*args, **kargs, &block)
          super
          @multi_args = true
        end

        def transform(*values)
          Array(values)
        end
      end
    end

    let(:transform) { MultipleArgument.new }

    it 'can be converted into a proc and called' do
      expect(transform.to_proc.call(1, 2)).to eq [1, 2]
    end

    it 'can be called directly' do
      expect(transform.call(1, 2)).to eq [1, 2]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
remi-0.2.39 spec/transform_spec.rb
remi-0.2.38 spec/transform_spec.rb
remi-0.2.37 spec/transform_spec.rb
remi-0.2.36 spec/transform_spec.rb