spec/form_spec.rb in rasti-form-3.1.0 vs spec/form_spec.rb in rasti-form-3.1.1
- old
+ new
@@ -38,11 +38,11 @@
point.assigned?(:y).must_equal false
end
it 'Invalid attributes' do
error = proc { point_class.new z: 3 }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"z":["unexpected attribute"]}'
+ error.message.must_equal "Validation errors:\n- z: [\"unexpected attribute\"]\n#<Rasti::Form[]>"
end
describe 'Casting' do
it 'Attribute' do
@@ -84,20 +84,20 @@
attribute :boolean, Rasti::Form::Types::Boolean
attribute :number, Rasti::Form::Types::Integer
end
error = proc { form.new boolean: 'x', number: 'y' }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"boolean":["Invalid cast: \'x\' -> Rasti::Form::Types::Boolean"],"number":["Invalid cast: \'y\' -> Rasti::Form::Types::Integer"]}'
+ error.message.must_equal "Validation errors:\n- boolean: [\"Invalid cast: \'x\' -> Rasti::Form::Types::Boolean\"]\n- number: [\"Invalid cast: \'y\' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
end
it 'Invalid nested attributes' do
form = build_form do
attribute :range, Rasti::Form::Types::Form[min: Rasti::Form::Types::Integer, max: Rasti::Form::Types::Integer]
end
error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
end
it 'Invalid form attributes' do
range = build_form do
attribute :min, Rasti::Form::Types::Integer
@@ -107,11 +107,11 @@
form = build_form do
attribute :range, Rasti::Form::Types::Form[range]
end
error = proc { form.new range: {min: 'x', max: 'y'} }.must_raise Rasti::Form::ValidationError
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"range.min\":[\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"],\"range.max\":[\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]}"
+ error.message.must_equal "Validation errors:\n- range.min: [\"Invalid cast: 'x' -> Rasti::Form::Types::Integer\"]\n- range.max: [\"Invalid cast: 'y' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
end
end
end
@@ -153,11 +153,11 @@
end
proc { form.new text: 'text' }.must_be_silent
error = proc { form.new }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"text":["Invalid text"]}'
+ error.message.must_equal "Validation errors:\n- text: [\"Invalid text\"]\n#<Rasti::Form[]>"
end
it 'Required' do
form = build_form do
attribute :text, Rasti::Form::Types::String
@@ -168,11 +168,11 @@
end
proc { form.new text: 'text' }.must_be_silent
error = proc { form.new }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"text":["not present"]}'
+ error.message.must_equal "Validation errors:\n- text: [\"not present\"]\n#<Rasti::Form[]>"
end
it 'Required when cast failed' do
form = build_form do
attribute :number, Rasti::Form::Types::Integer
@@ -183,11 +183,11 @@
end
proc { form.new number: 1 }.must_be_silent
error = proc { form.new number: 'text' }.must_raise Rasti::Form::ValidationError
- error.message.must_equal "Validation error: #<Rasti::Form[]> {\"number\":[\"Invalid cast: 'text' -> Rasti::Form::Types::Integer\"]}"
+ error.message.must_equal "Validation errors:\n- number: [\"Invalid cast: 'text' -> Rasti::Form::Types::Integer\"]\n#<Rasti::Form[]>"
end
it 'Not required' do
form = build_form do
attribute :text, Rasti::Form::Types::String
@@ -198,11 +198,11 @@
end
proc { form.new }.must_be_silent
error = proc { form.new text: 'text' }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[text: "text"]> {"text":["is present"]}'
+ error.message.must_equal "Validation errors:\n- text: [\"is present\"]\n#<Rasti::Form[text: \"text\"]>"
end
it 'Not empty string' do
form = build_form do
attribute :text, Rasti::Form::Types::String
@@ -213,11 +213,11 @@
end
proc { form.new text: 'text' }.must_be_silent
error = proc { form.new text: ' ' }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[text: " "]> {"text":["is empty"]}'
+ error.message.must_equal "Validation errors:\n- text: [\"is empty\"]\n#<Rasti::Form[text: \" \"]>"
end
it 'Not empty array' do
form = build_form do
attribute :array, Rasti::Form::Types::Array[Rasti::Form::Types::String]
@@ -228,11 +228,11 @@
end
proc { form.new array: ['text'] }.must_be_silent
error = proc { form.new array: [] }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[array: []]> {"array":["is empty"]}'
+ error.message.must_equal "Validation errors:\n- array: [\"is empty\"]\n#<Rasti::Form[array: []]>"
end
it 'Included in values list' do
form = build_form do
attribute :text, Rasti::Form::Types::String
@@ -243,11 +243,11 @@
end
proc { form.new text: 'value_1' }.must_be_silent
error = proc { form.new text: 'xyz' }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[text: "xyz"]> {"text":["not included in \'value_1\', \'value_2\'"]}'
+ error.message.must_equal "Validation errors:\n- text: [\"not included in \'value_1\', \'value_2\'\"]\n#<Rasti::Form[text: \"xyz\"]>"
end
it 'Time range' do
form = build_form do
attribute :from, Rasti::Form::Types::Time['%Y-%m-%d %H:%M:%S %Z']
@@ -262,11 +262,11 @@
to = Time.parse '2018-01-01 15:30:00'
proc { form.new from: from, to: to }.must_be_silent
error = proc { form.new from: to.to_s, to: from.to_s }.must_raise Rasti::Form::ValidationError
- error.message.must_equal "Validation error: #<Rasti::Form[from: #{to}, to: #{from}]> {\"from\":[\"invalid time range\"]}"
+ error.message.must_equal "Validation errors:\n- from: [\"invalid time range\"]\n#<Rasti::Form[from: #{to}, to: #{from}]>"
end
it 'Nested form' do
form = build_form do
attribute :range, Rasti::Form::Types::Form[min: Rasti::Form::Types::Integer, max: Rasti::Form::Types::Integer]
@@ -278,11 +278,11 @@
end
proc { form.new range: {min: 1, max: 2} }.must_be_silent
error = proc { form.new }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["not present"],"range.max":["not present"]}'
+ error.message.must_equal "Validation errors:\n- range.min: [\"not present\"]\n- range.max: [\"not present\"]\n#<Rasti::Form[]>"
end
it 'Nested validation' do
range = build_form do
attribute :min, Rasti::Form::Types::Integer
@@ -298,10 +298,10 @@
end
proc { form.new range: {min: 1, max: 2} }.must_be_silent
error = proc { form.new range: {min: 2, max: 1} }.must_raise Rasti::Form::ValidationError
- error.message.must_equal 'Validation error: #<Rasti::Form[]> {"range.min":["Min must be less than Max"]}'
+ error.message.must_equal "Validation errors:\n- range.min: [\"Min must be less than Max\"]\n#<Rasti::Form[]>"
end
end
describe 'Comparable' do
\ No newline at end of file