Sha256: a33da3949b86e9fb3a78be03ab5f402dcef3b3f68dce68609d5fac246876158d
Contents?: true
Size: 994 Bytes
Versions: 19
Compression:
Stored size: 994 Bytes
Contents
RSpec.describe 'Check depending on a nested value from a hash' do subject(:schema) do Dry::Validation.Schema do required(:tag).schema do required(:color).schema do required(:value).filled(:str?) end end rule(tag: [[:tag, :color, :value]]) do |value| value.eql?('red') end end end it 'passes when check passes' do expect(schema.(tag: { color: { value: 'red' }})).to be_success end it 'skips check when parent of the dependency failed' do expect(schema.(tag: { color: :oops }).messages).to eql( tag: { color: ['must be a hash'] } ) end it 'skips check when dependency failed' do expect(schema.(tag: { color: { value: :oops }}).messages).to eql( tag: { color: { value: ['must be a string'] } } ) end it 'fails when check fails' do expect(schema.(tag: { color: { value: 'blue' }}).messages).to eql( tag: { color: { value: ['must be equal to red'] } } ) end end
Version data entries
19 entries across 19 versions & 1 rubygems