Created
August 29, 2016 15:47
-
-
Save cored/ed5ed311c027812b143e3f27039b5a50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context "structs" do | |
subject(:schema) do | |
Dry::Validation.Schema do | |
required(:person).filled(Person) | |
end | |
end | |
class Name < Dry::Struct::Value | |
attribute :given_name, 'strict.string' | |
attribute :family_name, 'strict.string' | |
end | |
class Person < Dry::Struct::Value | |
attribute :name, Name | |
end | |
it 'handles nested structs' do | |
expect(schema.(person: { name: { given_name: 'Tim', family_name: 'Cooper' } })).to be_success | |
end | |
it 'fails when input is not valid' do | |
expect(schema.(person: {name: {given_name: 'Tim'}}).messages).to eq( | |
person: { name: { family_name: ["is missing"] } } | |
) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment