Sha256: 15d57ef27f7c3089866a595da3eee2ffd4bd22a2b5237a50b5d125e7ab94932d
Contents?: true
Size: 1.34 KB
Versions: 1
Compression:
Stored size: 1.34 KB
Contents
require 'minitest_helper' describe Rasti::Form::Types::Form do form = Rasti::Form[x: Rasti::Form::Types::Integer, y: Rasti::Form::Types::Integer] hash = {x: '1', y: '2', z: '3'} it 'Class' do result = Rasti::Form::Types::Form[form].cast hash result.must_be_instance_of form result.x.must_equal 1 result.y.must_equal 2 end it 'Inline' do type = Rasti::Form::Types::Form[x: Rasti::Form::Types::Integer, y: Rasti::Form::Types::Integer] result = type.cast hash result.must_be_instance_of type.form_class result.x.must_equal 1 result.y.must_equal 2 end it 'Invalid form class' do error = proc { Rasti::Form::Types::Form[1] }.must_raise ArgumentError error.message.must_equal 'Invalid form specification: 1' end [nil, 'text', :symbol, 1, [1,2], Object.new].each do |value| it "#{value.inspect} -> CastError" do error = proc { Rasti::Form::Types::Form[form].cast(value) }.must_raise Rasti::Form::CastError error.message.must_equal "Invalid cast: #{as_string(value)} -> #{Rasti::Form::Types::Form[form]}" end end it '{x: "text"} -> ValidationError' do error = proc { Rasti::Form::Types::Form[form].cast x: 'test' }.must_raise Rasti::Form::ValidationError error.message.must_equal "Validation error: {\"x\":[\"Invalid cast: 'test' -> Rasti::Form::Types::Integer\"]}" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rasti-form-0.1.0 | spec/types/form_spec.rb |