Sha256: 6ccc3f81d93fca94c0f07a61bdcb8eb51ca3cc89ae44b3bf3f490b1119324490
Contents?: true
Size: 1.36 KB
Versions: 13
Compression:
Stored size: 1.36 KB
Contents
require 'dry/validation/messages/i18n' RSpec.describe Dry::Validation, 'with localized messages' do before do I18n.config.available_locales_set << :pl I18n.load_path.concat(%w(en pl).map { |l| SPEC_ROOT.join("fixtures/locales/#{l}.yml") }) I18n.backend.load_translations end describe 'defining schema' do context 'without a namespace' do subject(:schema) do Dry::Validation.Schema do configure do config.messages = :i18n end required(:email) { |email| email.filled? } end end describe '#messages' do it 'returns localized error messages' do expect(schema.(email: '').messages(locale: :pl)).to eql( email: ['Proszę podać adres email'] ) end end end context 'with a namespace' do subject(:schema) do Dry::Validation.Schema do configure do configure do |config| config.messages = :i18n config.namespace = :user end end required(:email) { |email| email.filled? } end end describe '#messages' do it 'returns localized error messages' do expect(schema.(email: '').messages(locale: :pl)).to eql( email: ['Hej user! Dawaj ten email no!'] ) end end end end end
Version data entries
13 entries across 13 versions & 1 rubygems