Sha256: ea2d1c331ee32ee9aa4f44a7348c63b66ff0274f6fb8f0d2db81438f8cef3ce7
Contents?: true
Size: 981 Bytes
Versions: 1
Compression:
Stored size: 981 Bytes
Contents
RSpec.describe 'Check depending on a nested value from a hash' do subject(:schema) do Dry::Validation.Schema do key(:tag).schema do key(:color).schema do key(:value).required(:str?) end end rule(red: [[: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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dry-validation-0.7.4 | spec/integration/schema/check_with_nested_el_spec.rb |