spec/requests/glossary/destroy_spec.rb in deepl-rb-2.5.3 vs spec/requests/glossary/destroy_spec.rb in deepl-rb-3.0.0

- old
+ new

@@ -1,50 +1,66 @@ +# 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::Destroy do + subject(:destroy) { 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) { '367eef44-b533-4d95-be19-74950c7760e9' } - subject { DeepL::Requests::Glossary::Destroy.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(destroy).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 + context 'when performing a valid request' do + subject(:destroy) { described_class.new(api, new_glossary.id) } + let(:new_glossary) do DeepL::Requests::Glossary::Create.new(api, 'fixture', 'EN', 'ES', [%w[Hello Hola]]).request end - subject { DeepL::Requests::Glossary::Destroy.new(api, new_glossary.id) } - it 'should return an empty object' do - response = subject.request + + it 'returns an empty object' do + response = destroy.request expect(response).to eq(new_glossary.id) end end - context 'When deleting a non existing glossary with a valid id' do + context 'when deleting a non existing glossary with a valid id' do + subject(:destroy) { described_class.new(api, id) } + let(:id) { '00000000-0000-0000-0000-000000000000' } - subject { DeepL::Requests::Glossary::Destroy.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 { destroy.request }.to raise_error(DeepL::Exceptions::NotFound) end end - context 'When deleting a non existing glossary with an invalid id' do + context 'when deleting a non existing glossary with an invalid id' do + subject(:destroy) { described_class.new(api, id) } + let(:id) { 'invalid-uuid' } - subject { DeepL::Requests::Glossary::Destroy.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 { destroy.request }.to raise_error(DeepL::Exceptions::BadRequest) end end end end