Sha256: ca46a4a898a542c4cc2846d76cf3b23f325bf3ea83b5d5db45d79cd40a09efd3

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

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

    let(:type){ SetType.new(byte) }

    subject{ type.dress(arg) }

    context 'with an empty array' do
      let(:arg){ [] }

      it{ should eq([].to_set) }
    end

    context 'with a valid array' do
      let(:arg){ [12, 16] }

      it{ should eq([12, 16].to_set) }
    end

    context 'with not a enumerable' do
      let(:arg){ "foo" }

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

    context 'with an array with non bytes' do
      let(:arg){ [2, 4, -12] }

      subject{
        type.dress(arg) rescue $!
      }

      it 'should raise an error' do
        subject.should be_a(TypeError)
        subject.message.should eq("Invalid value `-12` for Byte")
      end

      it 'should have correct location' do
        subject.location.should eq("2")
      end
    end

    context 'with an array with duplicates' do
      let(:arg){ [2, 4, 2] }

      subject{
        type.dress(arg) rescue $!
      }

      it 'should raise an error' do
        subject.should be_a(TypeError)
        subject.message.should eq("Duplicate value `2`")
      end

      it 'should have correct location' do
        subject.location.should eq("2")
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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