Sha256: b8f7504a37faabca23022938fe6c3924072eeec010e495c5a4c6bda8d1b37b9b

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'
module Alf
  describe Heading do

    describe "the class itself" do
      let(:type){ Heading }
      def Heading.exemplars
        [
          {},
          {:a => String},
          {:a => String, :b => Date}
        ].map{|x| Heading.coerce(x)}
      end
      it_should_behave_like 'A valid type implementation'
    end

    let(:h0){ Heading.new({}) }
    let(:h1){ Heading.new(:name => String) }
    let(:h2){ Heading.new(:name => String, :price => Float) }

    it 'should be Enumerable' do
      h2.map{|k,v| [k,v]}.to_set.should eq([[:name, String], [:price, Float]].to_set)
    end

    describe "[]" do

      specify "it should mimic coerce" do
        Heading[:name => String].should eq(h1)
        Heading["name" => "String"].should eq(h1)
        Heading[{}].should eq(h0)
        Heading[[]].should eq(h0)
        Heading[["name", "String"]].should eq(h1)
      end

      specify "should raise ArgumentError on error" do
        lambda{ Heading[true] }.should raise_error(TypeError)
      end

    end # []

    describe "EMPTY" do
      subject{ Heading::EMPTY }
      it{ should be_a(Heading) }
      it_should_behave_like "A value"
    end

    describe "h0" do
      subject{ h0 }
      it { should == Heading::EMPTY }
      it_should_behave_like "A value" 
    end

    describe "h1" do
      subject{ h1 }
      it_should_behave_like "A value" 
    end

  end 
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-types/test_heading.rb
alf-core-0.14.0 spec/unit/alf-types/test_heading.rb
alf-core-0.13.1 spec/unit/alf-types/test_heading.rb
alf-core-0.13.0 spec/unit/alf-types/test_heading.rb