Sha256: 84d5af8b4f18fe74363d57d26b726b5375b7d51a8154fe1b7ace909f7c6c90a9

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

describe Transproc::Conditional do
  describe '.not' do
    let(:fn) { described_class.t(:not, -> value { value.is_a? String }) }
    subject  { fn[input] }

    context 'when predicate returns truthy value' do
      let(:input)  { 'foo' }
      let(:output) { false }

      it 'applies the first transformation' do
        expect(subject).to eql output
      end
    end

    context 'when predicate returns falsey value' do
      let(:input)  { :foo }
      let(:output) { true }

      it 'applies the first transformation' do
        expect(subject).to eql output
      end
    end
  end

  describe '.guard' do
    let(:fn) { described_class.t(:guard, condition, operation) }
    let(:condition) { ->(value) { value.is_a?(::String) } }
    let(:operation) { Transproc::Coercions.t(:to_integer) }

    context 'when predicate returns truthy value' do
      it 'applies the transformation and returns the result' do
        input = '2'

        expect(fn[input]).to eql(2)
      end
    end

    context 'when predicate returns falsey value' do
      it 'returns the original value' do
        input = { 'foo' => 'bar' }

        expect(fn[input]).to eql('foo' => 'bar')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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