Sha256: 1f212501b49626fce4275dc7e525fa56ade1339ad672ff450808f272261c7a0f

Contents?: true

Size: 888 Bytes

Versions: 13

Compression:

Stored size: 888 Bytes

Contents

require 'minitest_helper'

describe Rasti::Form::Types::Enum do

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

  [:a, 'b', "c"].each do |value|
    it "#{value.inspect} -> #{enum}" do
      Rasti::Form::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::Form::Types::Enum[:a,:b,:c].cast(value) }.must_raise Rasti::Form::CastError
      error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Enum[\"a\", \"b\", \"c\"]"
    end
  end

  it 'Constants' do
    enum = Rasti::Form::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

13 entries across 13 versions & 1 rubygems

Version Path
rasti-form-3.1.2 spec/types/enum_spec.rb
rasti-form-3.1.1 spec/types/enum_spec.rb
rasti-form-3.1.0 spec/types/enum_spec.rb
rasti-form-3.0.0 spec/types/enum_spec.rb
rasti-form-2.2.0 spec/types/enum_spec.rb
rasti-form-2.1.0 spec/types/enum_spec.rb
rasti-form-2.0.0 spec/types/enum_spec.rb
rasti-form-1.1.1 spec/types/enum_spec.rb
rasti-form-1.1.0 spec/types/enum_spec.rb
rasti-form-1.0.3 spec/types/enum_spec.rb
rasti-form-1.0.2 spec/types/enum_spec.rb
rasti-form-1.0.1 spec/types/enum_spec.rb
rasti-form-1.0.0 spec/types/enum_spec.rb