Sha256: cb90baaa956a1d9f6e9e73d788f80ddef14a47f71aea1347d8bedc35821404c8

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'
module Finitio
  describe "Using Finitio's abstract data types in Ruby" do

    let(:color) do
      Class.new{
        extend Finitio::DataType

        def initialize(r, g, b)
          @r, @g, @b = r, g, b
        end
        attr_reader :r, :g, :b

        def to_rgb
          { r: @r, g: @g, b: @b }
        end

        def self.rgb(tuple)
          new(tuple[:r], tuple[:g], tuple[:b])
        end

        contract :rgb, {r: 0..255, g: 0..255, b: 0..255}
      }
    end

    describe 'The factored class' do
      subject{ color }

      it{ should be_a(Class) }
    end

    describe 'the dress method, when valid' do

      subject{
        color.dress(r: 12, g: 13, b: 28)
      }

      it{ should be_a(color) }

      it 'should set the instance variables correctly' do
        subject.r.should eq(12)
        subject.g.should eq(13)
        subject.b.should eq(28)
      end
    end

    describe 'the up method, when already a color' do
      let(:value){
        color.new(12, 13, 28)
      }

      subject{
        color.dress(value)
      }

      it{ should be(value) }
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
finitio-0.4.1 spec/acceptance/ad_type/test_in_ruby.rb
finitio-0.4.0 spec/acceptance/ad_type/test_in_ruby.rb