Sha256: c6317e90a09c174958b37250cc295cf31698bb5fb24388965e81c0c826abbf69

Contents?: true

Size: 1.25 KB

Versions: 18

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'
module Finitio
  describe TypeFactory, "Factory#sub_type" do

    let(:factory){ TypeFactory.new }

    shared_examples_for "The 1..10 type" do

      it{ should be_a(SubType) }

      it 'should have the BuiltinType(Fixnum) super type' do
        expect(subject.super_type).to be_a(BuiltinType)
        expect(subject.super_type.ruby_type).to be(Fixnum)
      end

      it 'should have the correct constraint' do
        expect(subject.dress(10)).to eq(10)
        expect{ subject.dress(-12) }.to raise_error(TypeError)
        expect{ subject.dress(12) }.to raise_error(TypeError)
      end
    end

    context 'when use with a ruby class and a block' do
      subject{
        factory.type(Fixnum){|i| i>=0 and i<=10 }
      }

      it_should_behave_like "The 1..10 type"
    end

    context 'when use with a a range' do
      subject{
        factory.type(1..10)
      }

      it_should_behave_like "The 1..10 type"
    end

    context 'when use with a regexp' do
      subject{
        factory.type(/[a-z]+/)
      }

      it { should be_a(SubType) }

      it 'should have the correct constraint' do
        expect(subject.dress('abc')).to eq('abc')
        expect{ subject.dress('123') }.to raise_error(TypeError)
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
finitio-0.11.4 spec/type_factory/factory/test_sub_type.rb
finitio-0.11.3 spec/type_factory/factory/test_sub_type.rb
finitio-0.11.2 spec/type_factory/factory/test_sub_type.rb
finitio-0.11.1 spec/type_factory/factory/test_sub_type.rb
finitio-0.10.0 spec/type_factory/factory/test_sub_type.rb
finitio-0.9.1 spec/type_factory/factory/test_sub_type.rb
finitio-0.9.0 spec/type_factory/factory/test_sub_type.rb
finitio-0.8.0 spec/type_factory/factory/test_sub_type.rb
finitio-0.7.0 spec/type_factory/factory/test_sub_type.rb
finitio-0.7.0.pre.rc4 spec/type_factory/factory/test_sub_type.rb
finitio-0.7.0.pre.rc3 spec/type_factory/factory/test_sub_type.rb
finitio-0.7.0.pre.rc2 spec/type_factory/factory/test_sub_type.rb
finitio-0.7.0.pre.rc1 spec/type_factory/factory/test_sub_type.rb
finitio-0.6.1 spec/type_factory/factory/test_sub_type.rb
finitio-0.6.0 spec/type_factory/factory/test_sub_type.rb
finitio-0.5.2 spec/type_factory/factory/test_sub_type.rb
finitio-0.5.1 spec/type_factory/factory/test_sub_type.rb
finitio-0.5.0 spec/type_factory/factory/test_sub_type.rb