spec/requests/glossary/entries_spec.rb in deepl-rb-2.5.3 vs spec/requests/glossary/entries_spec.rb in deepl-rb-3.0.0
- old
+ new
@@ -1,48 +1,62 @@
+# 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::Entries do
+ subject(:entries_obj) { described_class.new(api, id) }
+
+ 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) { '012a5576-b551-4d4c-b917-ce01bc8debb6' }
- subject { DeepL::Requests::Glossary::Entries.new(api, id) }
+ let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
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(entries_obj).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 list of entries in TSV format' do
- entries = subject.request
- expect(entries).to be_kind_of(Array)
+ context 'when performing a valid request' do
+ it 'returns a list of entries in TSV format' do
+ entries = entries_obj.request
+ expect(entries).to be_a(Array)
expect(entries).to all(be_a(Array))
expect(entries.size).to eq(2)
end
end
- context 'When requesting entries with a valid but non existing glossary id' do
+ context 'when requesting entries with a valid but non existing glossary id' do
+ subject(:entries_obj) { described_class.new(api, id) }
+
let(:id) { '00000000-0000-0000-0000-000000000000' }
- subject { DeepL::Requests::Glossary::Entries.new(api, id) }
- 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 { entries_obj.request }.to raise_error(DeepL::Exceptions::NotFound)
end
end
- context 'When requesting entries with an invalid glossary id' do
+ context 'when requesting entries with an invalid glossary id' do
+ subject(:entries_obj) { described_class.new(api, id) }
+
let(:id) { 'invalid-uuid' }
- subject { DeepL::Requests::Glossary::Entries.new(api, id) }
- 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 { entries_obj.request }.to raise_error(DeepL::Exceptions::BadRequest)
end
end
end
end