spec/requests/glossary/find_spec.rb in deepl-rb-2.5.3 vs spec/requests/glossary/find_spec.rb in deepl-rb-3.0.0
- old
+ new
@@ -1,54 +1,68 @@
+# 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::Find do
+ subject(:glossary_find) { described_class.new(api, id, 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(:id) { 'd9ad833f-c818-430c-a3c9-47071384fa3e' }
+ let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
let(:options) { {} }
- subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
describe '#initialize' do
- context 'When building a request' do
- it 'should create a request object' do
- expect(subject).to be_a(described_class)
+ context 'when building a request' do
+ it 'creates a request object' do
+ expect(glossary_find).to be_a(described_class)
end
end
end
describe '#request' do
around do |example|
VCR.use_cassette('glossaries') { example.call }
end
- context 'When performing a valid request' do
- it 'should return a glossary object' do
- glossary = subject.request
+ context 'when performing a valid request' do
+ it 'returns a glossary object' do
+ glossary = glossary_find.request
expect(glossary).to be_a(DeepL::Resources::Glossary)
- expect(glossary.id).to eq('d9ad833f-c818-430c-a3c9-47071384fa3e')
+ expect(glossary.id).to eq('9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb')
expect(glossary.name).to eq('Mi Glosario')
expect(glossary.ready).to be(true).or be(false)
expect(glossary.source_lang).to eq('en')
expect(glossary.target_lang).to eq('es')
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
expect(glossary.entry_count).to eq(2)
end
end
- context 'When requesting a non existing glossary with a valid id' do
+ context 'when requesting a non existing glossary with a valid id' do
+ subject(:glossary_find) { described_class.new(api, id, options) }
+
let(:id) { 'a0af40e1-d81b-4aab-a95c-7cafbcfd1eb1' }
- subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
- it 'should raise a not found error' do
- expect { subject.request }.to raise_error(DeepL::Exceptions::NotFound)
+
+ it 'raises a not found error' do
+ expect { glossary_find.request }.to raise_error(DeepL::Exceptions::NotFound)
end
end
- context 'When requesting a non existing glossary with an invalid id' do
+ context 'when requesting a non existing glossary with an invalid id' do
+ subject(:glossary_find) { described_class.new(api, id, options) }
+
let(:id) { 'invalid-uuid' }
- subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
- it 'should raise a bad request error' do
- expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest)
+
+ it 'raises a bad request error' do
+ expect { glossary_find.request }.to raise_error(DeepL::Exceptions::BadRequest)
end
end
end
end