Sha256: 524afb82b0ad96a97abc39e0e61b5934f6d95b28d1e20392b4f27bc9c0e3c41f

Contents?: true

Size: 977 Bytes

Versions: 4

Compression:

Stored size: 977 Bytes

Contents

require 'spec_helper'

describe Transproc do
  describe 'composition' do
    it 'allows composing two transformation functions' do
      input = '1'
      output = 1.0

      to_i = Transproc(-> value { value.to_i })
      to_f = Transproc(-> value { value.to_f })

      result = to_i + to_f

      expect(result[input]).to eql(output)
    end
  end

  describe 'function registration' do
    it 'allows registering functions by name' do
      Transproc.register(:to_boolean, -> value { value == 'true' })

      result = Transproc(-> value { value.to_s }) + Transproc(:to_boolean)

      expect(result[:true]).to be(true)
      expect(result[:false]).to be(false)
    end

    it 'allows registering function by passing a block' do
      Transproc.register(:to_boolean) { |value| value == 'true' }

      result = Transproc(-> value { value.to_s }) + Transproc(:to_boolean)

      expect(result[:true]).to be(true)
      expect(result[:false]).to be(false)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
transproc-0.1.2 spec/integration/transproc_spec.rb
transproc-0.1.1 spec/integration/transproc_spec.rb
transproc-0.1.0 spec/integration/transproc_spec.rb
transproc-0.0.1 spec/integration/transproc_spec.rb