Sha256: a2a31d6a437b97c88aacebf0eca0e3bfcc3ff7c0d94a6ba8c93214fe5dba473d

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe DeepL do
  subject { DeepL.dup }

  describe '#configure' do
    context 'When providing no block' do
      let(:configuration) { DeepL::Configuration.new }
      before { subject.configure }

      it 'should use default configuration' do
        expect(subject.configuration).to eq(configuration)
      end
    end

    context 'When providing a valid configuration' do
      let(:configuration) do
        DeepL::Configuration.new(auth_key: 'VALID', host: 'http://www.example.org')
      end
      before do
        subject.configure do |config|
          config.auth_key = configuration.auth_key
          config.host = configuration.host
        end
      end

      it 'should use the provided configuration' do
        expect(subject.configuration).to eq(configuration)
      end
    end

    context 'When providing an invalid configuration' do
      it 'should raise an error' do
        expect { subject.configure { |c| c.auth_key = '' } }
          .to raise_error(DeepL::Exceptions::Error)
      end
    end
  end

  describe '#translate' do
    let(:input) { 'Sample' }
    let(:source_lang) { 'EN' }
    let(:target_lang) { 'ES' }

    around do |example|
      VCR.use_cassette('deepl_translate') { example.call }
    end

    context 'When translating a text' do
      it 'should create and call a request object' do
        expect(DeepL::Requests::TranslateText).to receive(:new)
          .with(subject.api, input, source_lang, target_lang).and_call_original

        text = subject.translate(input, source_lang: source_lang, target_lang: target_lang)
        expect(text).to be_a(DeepL::Resources::Text)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deepl-rb-0.0.1 spec/api/deepl_spec.rb
deepl-rb-0.0.0 spec/api/deepl_spec.rb