Sha256: 3ab513dd33d2e005185b63f763ea7363061e577e03af0d1b6e018e10a99ede2a

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

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

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

    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 } ])
      }

      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
qrb-0.2.0 spec/unit/type/ad_type/test_dress.rb
qrb-0.1.0 spec/unit/type/ad_type/test_dress.rb