Sha256: d127950a4b25c3dd0a5f0fb374fc2fc8c5a583d8dfd6e2b250ee1af3aa3672f1

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

# Copyright 2022 Daniel Herzog
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE.md file.
# frozen_string_literal: true

require 'spec_helper'

describe DeepL::Requests::Glossary::List do
  subject(:glossary_list) { described_class.new(api, options) }

  around do |tests|
    tmp_env = replace_env_preserving_deepl_vars_except_mock_server
    tests.call
    ENV.replace(tmp_env)
  end

  let(:api) { build_deepl_api }
  let(:options) { {} }

  describe '#initialize' do
    context 'when building a request' do
      it 'creates a request object' do
        expect(glossary_list).to be_a(described_class)
      end
    end
  end

  describe '#request' do
    around do |example|
      VCR.use_cassette('glossaries') { example.call }
    end

    context 'when requesting a list of all glossaries' do
      it 'returns a glossaries object' do
        glossaries = glossary_list.request
        expect(glossaries).to be_an(Array)
      end
    end

    context 'when performing a bad request' do
      context 'when using an invalid token' do
        let(:api) do
          api = build_deepl_api
          api.configuration.auth_key = 'invalid'
          api
        end

        it 'raises an unauthorized error' do
          expect { glossary_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deepl-rb-3.1.0 spec/requests/glossary/list_spec.rb
deepl-rb-3.0.2 spec/requests/glossary/list_spec.rb
deepl-rb-3.0.1 spec/requests/glossary/list_spec.rb
deepl-rb-3.0.0 spec/requests/glossary/list_spec.rb