Sha256: fda1c2e8cbc1800dca4fb4c7c6bff180ff199745b92aa7200a252d4605848e6c
Contents?: true
Size: 923 Bytes
Versions: 3
Compression:
Stored size: 923 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 'Values' 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' enum.values.must_equal ['first_value', 'SecondValue', 'THIRD_VALUE'] end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rasti-types-1.1.2 | spec/enum_spec.rb |
rasti-types-1.1.1 | spec/enum_spec.rb |
rasti-types-1.1.0 | spec/enum_spec.rb |