Sha256: f937e95a6204c7ca3497c46918bd94067776abd9961ab2fa04235eb44b2bb5ed
Contents?: true
Size: 1.7 KB
Versions: 2
Compression:
Stored size: 1.7 KB
Contents
require 'spec_helper' module Finitio describe "Using Finitio's abstract data types in Ruby/Finitio" do class MyColorClass 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 end let(:system) do Finitio.parse <<-EOF Byte = .Fixnum( i | i>=0 and i<= 255 ) Color = .Finitio::MyColorClass <rgb> {r: Byte, g: Byte, b: Byte} Gender = <mf> .String( s | s=='M' or s=='F' ) EOF end let(:color){ system["Color"] } describe 'the Color.dress method' do subject{ color.dress(arg) } context 'when valid' do let(:arg){ {"r" => 12, "g" => 17, "b" => 71} } it{ should be_a(MyColorClass) } it 'should be the expected one' do subject.r.should eq(12) subject.g.should eq(17) subject.b.should eq(71) end end context 'when invalid' do let(:arg){ {"r" => -12, "g" => 17, "b" => 71} } it 'should raise an error' do ->{ subject }.should raise_error(TypeError) end end end describe 'the Gender.dress method' do subject{ system['Gender'].dress(arg) } context 'when valid' do let(:arg){ 'M' } it{ should eq('M') } end context 'when valid' do let(:arg){ 'Monsieur' } it 'should raise an error' do ->{ subject }.should raise_error(TypeError, "Invalid value `Monsieur` for Gender") end end 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_finitio.rb |
finitio-0.4.0 | spec/acceptance/ad_type/test_in_finitio.rb |