Sha256: abcf9dc9c74d29dd5b5a8cfd0fd8c0e6448c282248e1c1fa919ebfb90c259fe5
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 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'} 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rasti-form-1.0.1 | spec/types/form_spec.rb |
rasti-form-1.0.0 | spec/types/form_spec.rb |