spec/lutaml/model/serializable_validation_spec.rb in lutaml-model-0.3.25 vs spec/lutaml/model/serializable_validation_spec.rb in lutaml-model-0.3.26

- old
+ new

@@ -1,9 +1,10 @@ require "spec_helper" class TestSerializable < Lutaml::Model::Serializable attribute :name, :string, values: ["Alice", "Bob", "Charlie"] + attribute :email, :string, pattern: /.*?\S+@.+\.\S+/ attribute :age, :integer, collection: 1..3 xml do root "test" map_element "name", to: :name @@ -25,13 +26,16 @@ map "age", to: :age end end RSpec.describe Lutaml::Model::Serializable do - let(:valid_instance) { TestSerializable.new(name: "Alice", age: [30]) } + let(:valid_instance) do + TestSerializable.new(name: "Alice", age: [30], email: "alice@gmail.com") + end + let(:invalid_instance) do - TestSerializable.new(name: "David", age: [25, 30, 35, 40]) + TestSerializable.new(name: "David", age: [25, 30, 35, 40], email: "david@gmail") end describe "serialization methods" do it "does not raise validation errors when calling to_xml" do expect { invalid_instance.to_xml }.not_to raise_error @@ -64,11 +68,12 @@ describe "validate method" do it "returns errors for invalid attributes" do errors = invalid_instance.validate expect(errors).not_to be_empty - expect(errors.first).to be_a(Lutaml::Model::InvalidValueError) - expect(errors.last).to be_a(Lutaml::Model::CollectionCountOutOfRangeError) + expect(errors[0]).to be_a(Lutaml::Model::InvalidValueError) + expect(errors[1]).to be_a(Lutaml::Model::PatternNotMatchedError) + expect(errors[2]).to be_a(Lutaml::Model::CollectionCountOutOfRangeError) end end describe "validate! method" do it "raises ValidationError for invalid attributes" do