Sha256: 399f4da43ca0e949723d00b2bcfd3e64c6e5eb833b0483c9a0d5d0a271b31fc5

Contents?: true

Size: 1.2 KB

Versions: 6

Compression:

Stored size: 1.2 KB

Contents

module LightServiceExt
  RSpec.describe ApplicationContract do
    let(:contract_class) do
      Class.new(ApplicationContract) do
        params do
          required(:email).maybe(:string)
        end

        rule(:email).validate(:email)
      end
    end

    describe '.keys' do
      it 'returns schema rule keys' do
        expect(contract_class.keys).to contain_exactly(:email)
      end
    end

    describe '.register_macro' do
      describe ':email' do
        let(:email) { nil }
        let(:params) { { email: email } }

        subject(:result) { contract_class.new.call(params) }

        context 'with valid email' do
          let(:email) { 'email@domain.com' }

          it 'returns success' do
            expect(result).to be_success
          end
        end

        context 'with invalid email' do
          let(:email) { 'emaildomain.com' }

          it 'returns failure' do
            expect(result).to be_failure

            errors = result.errors.to_h
            expect(errors.keys).to contain_exactly(:email)

            error_messages = errors[:email]
            expect(error_messages).to contain_exactly("must be a valid email")
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
light-service-ext-0.1.11 spec/light-service-ext/application_contract_spec.rb
light-service-ext-0.1.10 spec/light-service-ext/application_contract_spec.rb
light-service-ext-0.1.9 spec/light-service-ext/application_contract_spec.rb
light-service-ext-0.1.8 spec/light-service-ext/application_contract_spec.rb
light-service-ext-0.1.7 spec/light-service-ext/application_contract_spec.rb
light-service-ext-0.1.6 spec/light-service-ext/application_contract_spec.rb