Sha256: a7290051af30dc8c40ee546bf1ae2bbe5497eaef5b107a8f64c4de17f3371006

Contents?: true

Size: 1.15 KB

Versions: 19

Compression:

Stored size: 1.15 KB

Contents

require 'spec_helper'
module Finitio
  describe TypeFactory, "DSL#adt" do

    let(:factory){ TypeFactory.new }

    let(:contracts){
      { rgb: [intType,   Color.method(:rgb), Finitio::IDENTITY ],
        hex: [floatType, Color.method(:hex), Finitio::IDENTITY ]}
    }

    shared_examples_for "The <Color> type" do

      it{ should be_a(AdType) }

      it 'should have the correct ruby type' do
        expect(subject.ruby_type).to be(Color)
      end

      it 'should have the two contracts' do
        expect(subject.contracts.map(&:name)).to eq([:rgb, :hex])
      end
    end

    before do
      subject
    end

    context 'when used with the standard signature' do
      subject{
        factory.adt(Color, contracts)
      }

      it_should_behave_like "The <Color> type"

      it 'should have the correct name' do
        expect(subject.name).to eq("Color")
      end
    end

    context 'when used with a name' do
      subject{
        factory.adt(Color, contracts, "MyColor")
      }

      it_should_behave_like "The <Color> type"

      it 'should have the correct name' do
        expect(subject.name).to eq("MyColor")
      end
    end

  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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