Sha256: cebe6ce81bd03384e82d8d5790fee6cf2dceae468cb20ab3e48f2bce9a645095

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

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

    let(:factory){ TypeFactory.new }

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

    shared_examples_for "The <Color> type" do

      it{ should be_a(AdType) }

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

      it 'should have the two contracts' do
        subject.contracts.keys.should 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
        subject.name.should 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
        subject.name.should eq("MyColor")
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qrb-0.2.0 spec/unit/type_factory/dsl/test_adt.rb
qrb-0.1.0 spec/unit/type_factory/dsl/test_adt.rb