Sha256: 03675755dafa49eca0ce55bcbd5661bbbdb2e5bf40799c12c27a75ba56ccd63c

Contents?: true

Size: 1.08 KB

Versions: 25

Compression:

Stored size: 1.08 KB

Contents

require 'dry/validation/messages/i18n'

RSpec.describe Dry::Validation do
  shared_context 'schema with customized messages' do
    describe '#messages' do
      it 'returns compiled error messages' do
        expect(schema.(email: '').messages).to eql(
          email: ['Please provide your email']
        )
      end
    end
  end

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

        required(: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

      subject(:schema) do
        Dry::Validation.Schema do
          configure do
            config.messages = :i18n
          end

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

      include_context 'schema with customized messages'
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
dry-validation-0.13.2 spec/integration/custom_error_messages_spec.rb
dry-validation-0.13.1 spec/integration/custom_error_messages_spec.rb
dry-validation-0.11.2 spec/integration/custom_error_messages_spec.rb
dry-validation-0.12.3 spec/integration/custom_error_messages_spec.rb
dry-validation-0.13.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.12.2 spec/integration/custom_error_messages_spec.rb
dry-validation-0.12.1 spec/integration/custom_error_messages_spec.rb
dry-validation-0.12.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.11.1 spec/integration/custom_error_messages_spec.rb
dry-validation-0.11.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.7 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.6 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.5 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.4 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.3 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.2 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.1 spec/integration/custom_error_messages_spec.rb
dry-validation-0.10.0 spec/integration/custom_error_messages_spec.rb
dry-validation-0.9.5 spec/integration/custom_error_messages_spec.rb
dry-validation-0.9.4 spec/integration/custom_error_messages_spec.rb