Sha256: 848c6c33e0aeaf0347387708ffec12aa984f83ec14a00ae89eb8f7f0844ebab6

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

require 'minitest_helper'

describe Rasti::Types::Enum do

  enum = Rasti::Types::Enum[:a,:b,:c]

  [:a, 'b', "c"].each do |value|
    it "#{value.inspect} -> #{enum}" do
      Rasti::Types::Enum[:a,:b,:c].cast(value).must_equal value.to_s
    end
  end

  [nil, 'text', :symbol, '999'.to_sym, [1,2], {a: 1, b: 2}, Object.new].each do |value|
    it "#{value.inspect} -> CastError" do
      error = proc { Rasti::Types::Enum[:a,:b,:c].cast(value) }.must_raise Rasti::Types::CastError
      error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Types::Enum[\"a\", \"b\", \"c\"]"
    end
  end

  it 'Constants' do
    enum = Rasti::Types::Enum[:first_value, 'SecondValue', 'THIRD_VALUE']

    enum.first_value.must_equal 'first_value'
    enum.second_value.must_equal 'SecondValue'
    enum.third_value.must_equal 'THIRD_VALUE'
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rasti-types-1.0.0 spec/enum_spec.rb