Skip to content

Instantly share code, notes, and snippets.

@cored
Created August 29, 2016 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cored/ed5ed311c027812b143e3f27039b5a50 to your computer and use it in GitHub Desktop.
Save cored/ed5ed311c027812b143e3f27039b5a50 to your computer and use it in GitHub Desktop.
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