Sha256: c9d10200088485e34f8099be88759947d4479b1001701705509bb35fc10ad438
Contents?: true
Size: 868 Bytes
Versions: 2
Compression:
Stored size: 868 Bytes
Contents
require 'minitest_helper' describe Rasti::Types::TypedEnum do let(:enum) { Rasti::Types::TypedEnum[Colors] } it 'nil -> nil' do enum.cast(nil).must_equal nil end ['BLUE', 'GREEN', 'RED'].each do |value| it "#{value.inspect} -> #{value}" do enum.cast(value).must_equal Colors[value] end end ['text', :symbol, true, false, 100, Time.now, [1,2], {a: 1, b: 2}, Object.new].each do |value| it "#{value.inspect} -> CastError" do error = proc { enum.cast(value) }.must_raise Rasti::Types::CastError error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Types::TypedEnum[Colors]" end end it 'Values' do enum.blue.must_equal Colors::Blue.new enum.green.must_equal Colors::Green.new enum.red.must_equal Colors::Red.new enum.values.must_equal [enum.blue, enum.green, enum.red] end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rasti-types-2.0.1 | spec/typed_enum_spec.rb |
rasti-types-2.0.0 | spec/typed_enum_spec.rb |