Sha256: 60b1f29a2ff18980a3caccb8fa0e48b0468369f4463c30af674e5bdfd8d8dd38

Contents?: true

Size: 835 Bytes

Versions: 14

Compression:

Stored size: 835 Bytes

Contents

require 'minitest_helper'

describe Rasti::Form::Types::Hash do

  it "{'a' => '123'} -> {a: 123}" do
    Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer].cast('a' => '123').must_equal a: 123
  end

  it "{'1' => :abc} -> {1 => 'abc'}" do
    Rasti::Form::Types::Hash[Rasti::Form::Types::Integer, Rasti::Form::Types::String].cast('1' => :abc).must_equal 1 => 'abc'
  end

  [nil, 1, 'text', :symbol, {a: true}, Object.new].each do |value|
    it "#{value.inspect} -> CastError" do
      error = proc { Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer].cast(value) }.must_raise Rasti::Form::CastError
      error.message.must_equal "Invalid cast: #{as_string(value)} -> Rasti::Form::Types::Hash[Rasti::Form::Types::Symbol, Rasti::Form::Types::Integer]"
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

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