Sha256: 016707e5cab3c7ba45fc8d22c5b2da405ef95f1dc3c0e0c8990a3b2784a2801f

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

require 'dry/validation/messages/i18n'

RSpec.describe Dry::Validation do
  subject(:validation) { schema.new }

  shared_context 'schema with customized messages' do
    describe '#messages' do
      it 'returns compiled error messages' do
        expect(validation.(email: '').messages).to match_array([
          [:email, [['Please provide your email'], '']]
        ])
      end
    end
  end

  context 'yaml' do
    let(:schema) do
      Class.new(Dry::Validation::Schema) do
        configure do |config|
          config.messages_file = SPEC_ROOT.join('fixtures/locales/en.yml')
        end

        key(:email, &:filled?)
      end
    end

    include_context 'schema with customized messages'
  end

  context 'i18n' do
    context 'with custom messages set globally' do
      before do
        I18n.load_path << SPEC_ROOT.join('fixtures/locales/en.yml')
        I18n.backend.load_translations
      end

      let(:schema) do
        Class.new(Dry::Validation::Schema) do
          configure do |config|
            config.messages = :i18n
          end

          key(:email, &:filled?)
        end
      end

      include_context 'schema with customized messages'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-validation-0.6.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.5.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.4.1 spec/integration/custom_error_messages_spec.rb
dry-validation-0.4.0 spec/integration/custom_error_messages_spec.rb