Sha256: 0cc667fef60583968cce3cb5d2167b0a8af6973bdfbd948ed70fa6614fa0cf40

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe DeepL::Configuration do
  let(:attributes) { {} }
  subject { DeepL::Configuration.new(attributes) }

  describe '#initialize' do
    context 'When using default configuration attributes' do
      it 'should use default attributes' do
        expect(subject.auth_key).to eq(ENV.fetch('DEEPL_AUTH_KEY', nil))
        expect(subject.host).to eq('https://api.deepl.com')
        expect(subject.version).to eq('v2')
      end
    end

    context 'When using custom configuration attributes' do
      let(:attributes) { { auth_key: 'SAMPLE', host: 'https://api-free.deepl.com', version: 'v1' } }

      it 'should use custom attributes' do
        expect(subject.auth_key).to eq(attributes[:auth_key])
        expect(subject.host).to eq(attributes[:host])
        expect(subject.version).to eq(attributes[:version])
      end
    end
  end

  describe '#validate!' do
    let(:auth_message) { 'auth_key not provided' }

    context 'When providing a valid auth key' do
      let(:attributes) { { auth_key: '' } }

      it 'should raise an error' do
        expect { subject.validate! }.to raise_error(DeepL::Exceptions::Error, auth_message)
      end
    end

    context 'When providing an invalid auth key' do
      let(:attributes) { { auth_key: 'not-empty' } }

      it 'should not raise an error' do
        expect { subject.validate! }.not_to raise_error
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
deepl-rb-2.5.3 spec/api/configuration_spec.rb
deepl-rb-2.5.2 spec/api/configuration_spec.rb
deepl-rb-2.5.1 spec/api/configuration_spec.rb