Sha256: 88e7bce32e63777572c9d5da2c534172ee39cfab025a64a656f0922a3fb63085

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'
module Finitio
  describe AdType, 'dress' do

    let(:type){
      AdType.new(Color, rgb: [intType,   ->(i){ i*2 }, Finitio::IDENTITY ],
                        hex: [floatType, ->(f){ f*3 }, Finitio::IDENTITY ])
    }

    subject{
      type.dress(arg)
    }

    context 'with a color' do
      let(:arg){ Color.new(12, 13, 15) }

      it{ should be(arg) }
    end

    context 'with an integer' do
      let(:arg){ 12 }

      it{ should eq(24) }
    end

    context 'with a float' do
      let(:arg){ 12.0 }

      it{ should eq(36.0) }
    end

    context 'with an unrecognized' do
      let(:arg){ "foo" }

      it 'should raise an error' do
        ->{
          subject
        }.should raise_error(TypeError, "Invalid value `foo` for Color")
      end
    end

    context 'when the upper raises an error' do
      let(:type){
        AdType.new(Color, rgb: [ intType, ->(t){ raise ArgumentError }, Finitio::IDENTITY ])
      }

      it 'should hide the error' do
        err = type.dress(12) rescue $!
        err.should be_a(TypeError)
        err.message.should eq("Invalid value `12` for Color")
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finitio-0.4.1 spec/unit/type/ad_type/test_dress.rb
finitio-0.4.0 spec/unit/type/ad_type/test_dress.rb