Sha256: facbe2d9fb7d3c1ce0407f37e071a4964b8ed91ec9c8e0c0c247a6b01c4db57f
Contents?: true
Size: 931 Bytes
Versions: 5
Compression:
Stored size: 931 Bytes
Contents
RSpec.describe 'Schema with negated rules' do subject(:schema) do Dry::Validation.Schema do configure do def self.messages Messages.default.merge( en: { errors: { be_reasonable: 'you cannot eat cake and have cake!' } } ) end end optional(:eat_cake).required optional(:have_cake).required rule(:be_reasonable) do value(:eat_cake).eql?('yes!') & value(:have_cake).eql?('yes!').not end end end describe '#messages' do it 'passes when only one option is selected' do messages = schema.(eat_cake: 'yes!', have_cake: 'no!').messages[:be_reasonable] expect(messages).to be(nil) end it 'fails when both options are selected' do messages = schema.(eat_cake: 'yes!', have_cake: 'yes!').messages[:be_reasonable] expect(messages).to eql(['you cannot eat cake and have cake!']) end end end
Version data entries
5 entries across 5 versions & 1 rubygems