deepl-rb 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +3 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile +0 -2
- data/README.md +12 -12
- data/VERSION +1 -1
- data/deepl-rb.gemspec +27 -22
- data/lib/deepl/requests/rephrase.rb +3 -2
- data/lib/deepl/requests/translate.rb +2 -2
- data/lib/deepl.rb +7 -4
- data/lib/version.rb +1 -1
- data/spec/api/deepl_spec.rb +134 -332
- data/spec/integration_tests/document_api_spec.rb +4 -18
- data/spec/integration_tests/document_error_paths_spec.rb +33 -0
- data/spec/integration_tests/glossary_api_spec.rb +114 -0
- data/spec/integration_tests/glossary_error_paths_spec.rb +107 -0
- data/spec/integration_tests/languages_api_spec.rb +54 -0
- data/spec/integration_tests/languages_error_paths_spec.rb +25 -0
- data/spec/integration_tests/rephrase_api_spec.rb +90 -0
- data/spec/integration_tests/rephrase_error_paths_spec.rb +53 -0
- data/spec/integration_tests/smoke_test_spec.rb +24 -0
- data/spec/integration_tests/style_rule_api_spec.rb +1 -19
- data/spec/integration_tests/style_rule_error_paths_spec.rb +45 -0
- data/spec/integration_tests/translate_api_spec.rb +98 -0
- data/spec/integration_tests/translate_error_paths_spec.rb +48 -0
- data/spec/integration_tests/translation_memory_api_spec.rb +1 -17
- data/spec/integration_tests/translation_memory_error_paths_spec.rb +19 -0
- data/spec/integration_tests/usage_api_spec.rb +29 -0
- data/spec/integration_tests/usage_error_paths_spec.rb +18 -0
- data/spec/requests/glossary/create_spec.rb +0 -21
- data/spec/requests/glossary/destroy_spec.rb +0 -39
- data/spec/requests/glossary/entries_spec.rb +0 -35
- data/spec/requests/glossary/find_spec.rb +0 -40
- data/spec/requests/glossary/language_pairs_spec.rb +0 -13
- data/spec/requests/glossary/list_spec.rb +0 -27
- data/spec/requests/languages_spec.rb +0 -41
- data/spec/requests/rephrase_spec.rb +13 -139
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -24
- data/spec/requests/style_rule/create_spec.rb +0 -16
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -26
- data/spec/requests/style_rule/destroy_spec.rb +0 -27
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -27
- data/spec/requests/style_rule/find_spec.rb +0 -28
- data/spec/requests/style_rule/list_spec.rb +0 -31
- data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -21
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -26
- data/spec/requests/style_rule/update_spec.rb +0 -19
- data/spec/requests/translate_spec.rb +8 -217
- data/spec/requests/translation_memory/list_spec.rb +0 -34
- data/spec/requests/usage_spec.rb +0 -16
- data/spec/resources/custom_instruction_spec.rb +32 -0
- data/spec/resources/style_rule_spec.rb +68 -0
- data/spec/spec_helper.rb +15 -45
- data/spec/support/live_mock_server.rb +12 -0
- data/spec/support/managed_glossary.rb +17 -0
- data/spec/support/managed_style_rule.rb +17 -0
- data/spec/support/managed_translation_memory.rb +7 -0
- metadata +23 -21
- data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
- data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
- data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
- data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
- data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
- data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
- data/spec/fixtures/vcr_cassettes/style_rules.yml +0 -92
- data/spec/fixtures/vcr_cassettes/style_rules_crud.yml +0 -926
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10630
- data/spec/fixtures/vcr_cassettes/translation_memories.yml +0 -74
- data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.translate error paths' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
let(:text) { 'proton beam' }
|
|
12
|
+
|
|
13
|
+
describe 'authorization failures' do
|
|
14
|
+
it 'raises AuthorizationFailed when the auth key is invalid' do
|
|
15
|
+
request = DeepL::Requests::Translate.new(unauthorized_api, text, 'EN', 'DE')
|
|
16
|
+
|
|
17
|
+
expect { request.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'bad request errors' do
|
|
22
|
+
it 'raises BadRequest for an unsupported target language' do
|
|
23
|
+
expect { DeepL.translate(text, 'EN', 'ZZ') }
|
|
24
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'raises BadRequest when no target language is given' do
|
|
28
|
+
expect { DeepL.translate(text, 'EN', nil) }
|
|
29
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Real-server only: the mock coerces text:[null] to text:[""] and accepts it,
|
|
33
|
+
# so it cannot reproduce this; prod rejects [null] with 400.
|
|
34
|
+
it 'raises BadRequest when the text is nil', :real_server_only do
|
|
35
|
+
expect { DeepL.translate(nil, 'EN', 'DE') }
|
|
36
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'request entity too large errors' do
|
|
41
|
+
it 'raises RequestEntityTooLarge when too many texts are sent in a single request' do
|
|
42
|
+
texts = Array.new(10_000) { |i| "This is the sentence number #{i}" }
|
|
43
|
+
|
|
44
|
+
expect { DeepL.translate(texts, 'EN', 'DE') }
|
|
45
|
+
.to raise_error(DeepL::Exceptions::RequestEntityTooLarge)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -5,21 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
require 'spec_helper'
|
|
7
7
|
|
|
8
|
-
describe DeepL::TranslationMemoryApi do
|
|
9
|
-
before do
|
|
10
|
-
VCR.turn_off!
|
|
11
|
-
WebMock.allow_net_connect!
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
after do
|
|
15
|
-
VCR.turn_on!
|
|
16
|
-
WebMock.disable_net_connect!
|
|
17
|
-
end
|
|
18
|
-
|
|
8
|
+
describe DeepL::TranslationMemoryApi, :mock_server_only do
|
|
19
9
|
describe '#translate_with_translation_memory' do
|
|
20
10
|
it 'when performing a request with translation_memory_id' do
|
|
21
|
-
skip 'Only runs on mock server' if real_server?
|
|
22
|
-
|
|
23
11
|
source_lang = 'DE'
|
|
24
12
|
target_lang = 'EN'
|
|
25
13
|
text = 'Protonenstrahl'
|
|
@@ -31,8 +19,6 @@ describe DeepL::TranslationMemoryApi do
|
|
|
31
19
|
end
|
|
32
20
|
|
|
33
21
|
it 'when performing a request with translation_memory resource object' do
|
|
34
|
-
skip 'Only runs on mock server' if real_server?
|
|
35
|
-
|
|
36
22
|
source_lang = 'DE'
|
|
37
23
|
target_lang = 'EN'
|
|
38
24
|
text = 'Protonenstrahl'
|
|
@@ -46,8 +32,6 @@ describe DeepL::TranslationMemoryApi do
|
|
|
46
32
|
|
|
47
33
|
describe '#list_translation_memories' do
|
|
48
34
|
it 'when requesting a list of all translation memories' do
|
|
49
|
-
skip 'Only runs on mock server' if real_server?
|
|
50
|
-
|
|
51
35
|
translation_memories = DeepL.translation_memories.list
|
|
52
36
|
expect(translation_memories).to be_an(Array)
|
|
53
37
|
expect(translation_memories).not_to be_empty
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::TranslationMemoryApi, :mock_server_only do # rubocop:disable RSpec/SpecFilePathFormat
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
describe 'authorization failures' do
|
|
12
|
+
let(:unauthorized_translation_memories) { described_class.new(unauthorized_api) }
|
|
13
|
+
|
|
14
|
+
it 'raises AuthorizationFailed when listing with an invalid auth key' do
|
|
15
|
+
expect { unauthorized_translation_memories.list }
|
|
16
|
+
.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.usage' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
describe 'happy path' do
|
|
10
|
+
it 'returns a Usage resource with integer counters where count does not exceed limit' do
|
|
11
|
+
usage = DeepL.usage
|
|
12
|
+
|
|
13
|
+
expect(usage).to be_a(DeepL::Resources::Usage)
|
|
14
|
+
expect(usage).to respond_to(:character_count, :character_limit)
|
|
15
|
+
expect(usage.character_count).to be_an(Integer)
|
|
16
|
+
expect(usage.character_limit).to be_an(Integer)
|
|
17
|
+
expect(usage.character_count).to be <= usage.character_limit
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'resource shape' do
|
|
22
|
+
it 'exposes quota_exceeded? consistent with character_count vs character_limit' do
|
|
23
|
+
usage = DeepL.usage
|
|
24
|
+
|
|
25
|
+
expect(usage).to respond_to(:quota_exceeded?)
|
|
26
|
+
expect(usage.quota_exceeded?).to eq(usage.character_count >= usage.character_limit)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.usage error paths' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
describe 'authorization failures' do
|
|
12
|
+
it 'raises AuthorizationFailed when the auth key is invalid' do
|
|
13
|
+
request = DeepL::Requests::Usage.new(unauthorized_api)
|
|
14
|
+
|
|
15
|
+
expect { request.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -26,7 +26,6 @@ describe DeepL::Requests::Glossary::Create do
|
|
|
26
26
|
%w[World Mundo]
|
|
27
27
|
]
|
|
28
28
|
end
|
|
29
|
-
let(:entries_format) { 'tsv' }
|
|
30
29
|
let(:options) { {} }
|
|
31
30
|
|
|
32
31
|
describe '#initialize' do
|
|
@@ -42,24 +41,4 @@ describe DeepL::Requests::Glossary::Create do
|
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
|
-
|
|
46
|
-
describe '#request' do
|
|
47
|
-
around do |example|
|
|
48
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'when performing a valid request with two glossary entries' do
|
|
52
|
-
it 'returns a glossaries object' do
|
|
53
|
-
glossary = create.request
|
|
54
|
-
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
|
55
|
-
expect(glossary.id).to be_a(String)
|
|
56
|
-
expect(glossary.name).to eq('Mi Glosario')
|
|
57
|
-
expect(glossary.ready).to be(true).or be(false)
|
|
58
|
-
expect(glossary.source_lang).to eq('en')
|
|
59
|
-
expect(glossary.target_lang).to eq('es')
|
|
60
|
-
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
|
61
|
-
expect(glossary.entry_count).to eq(2)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
44
|
end
|
|
@@ -24,43 +24,4 @@ describe DeepL::Requests::Glossary::Destroy do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when performing a valid request' do
|
|
34
|
-
subject(:destroy) { described_class.new(api, new_glossary.id) }
|
|
35
|
-
|
|
36
|
-
let(:new_glossary) do
|
|
37
|
-
DeepL::Requests::Glossary::Create.new(api, 'fixture', 'EN', 'ES', [%w[Hello Hola]]).request
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'returns an empty object' do
|
|
41
|
-
response = destroy.request
|
|
42
|
-
expect(response).to eq(new_glossary.id)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when deleting a non existing glossary with a valid id' do
|
|
47
|
-
subject(:destroy) { described_class.new(api, id) }
|
|
48
|
-
|
|
49
|
-
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
|
50
|
-
|
|
51
|
-
it 'raises a not found error' do
|
|
52
|
-
expect { destroy.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context 'when deleting a non existing glossary with an invalid id' do
|
|
57
|
-
subject(:destroy) { described_class.new(api, id) }
|
|
58
|
-
|
|
59
|
-
let(:id) { 'invalid-uuid' }
|
|
60
|
-
|
|
61
|
-
it 'raises a bad request error' do
|
|
62
|
-
expect { destroy.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
27
|
end
|
|
@@ -24,39 +24,4 @@ describe DeepL::Requests::Glossary::Entries do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when performing a valid request' do
|
|
34
|
-
it 'returns a list of entries in TSV format' do
|
|
35
|
-
entries = entries_obj.request
|
|
36
|
-
expect(entries).to be_a(Array)
|
|
37
|
-
expect(entries).to all(be_a(Array))
|
|
38
|
-
expect(entries.size).to eq(2)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when requesting entries with a valid but non existing glossary id' do
|
|
43
|
-
subject(:entries_obj) { described_class.new(api, id) }
|
|
44
|
-
|
|
45
|
-
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
|
46
|
-
|
|
47
|
-
it 'raises a not found error' do
|
|
48
|
-
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'when requesting entries with an invalid glossary id' do
|
|
53
|
-
subject(:entries_obj) { described_class.new(api, id) }
|
|
54
|
-
|
|
55
|
-
let(:id) { 'invalid-uuid' }
|
|
56
|
-
|
|
57
|
-
it 'raises a bad request error' do
|
|
58
|
-
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
27
|
end
|
|
@@ -25,44 +25,4 @@ describe DeepL::Requests::Glossary::Find do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
|
|
29
|
-
describe '#request' do
|
|
30
|
-
around do |example|
|
|
31
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when performing a valid request' do
|
|
35
|
-
it 'returns a glossary object' do
|
|
36
|
-
glossary = glossary_find.request
|
|
37
|
-
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
|
38
|
-
expect(glossary.id).to eq('9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb')
|
|
39
|
-
expect(glossary.name).to eq('Mi Glosario')
|
|
40
|
-
expect(glossary.ready).to be(true).or be(false)
|
|
41
|
-
expect(glossary.source_lang).to eq('en')
|
|
42
|
-
expect(glossary.target_lang).to eq('es')
|
|
43
|
-
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
|
44
|
-
expect(glossary.entry_count).to eq(2)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'when requesting a non existing glossary with a valid id' do
|
|
49
|
-
subject(:glossary_find) { described_class.new(api, id, options) }
|
|
50
|
-
|
|
51
|
-
let(:id) { 'a0af40e1-d81b-4aab-a95c-7cafbcfd1eb1' }
|
|
52
|
-
|
|
53
|
-
it 'raises a not found error' do
|
|
54
|
-
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'when requesting a non existing glossary with an invalid id' do
|
|
59
|
-
subject(:glossary_find) { described_class.new(api, id, options) }
|
|
60
|
-
|
|
61
|
-
let(:id) { 'invalid-uuid' }
|
|
62
|
-
|
|
63
|
-
it 'raises a bad request error' do
|
|
64
|
-
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
28
|
end
|
|
@@ -24,17 +24,4 @@ describe DeepL::Requests::Glossary::LanguagePairs do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting a list of all language pairs supported by glossaries' do
|
|
34
|
-
it 'returns a language pairs object' do
|
|
35
|
-
language_pairs = language_pairs_obj.request
|
|
36
|
-
expect(language_pairs).to be_an(Array)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
27
|
end
|
|
@@ -24,31 +24,4 @@ describe DeepL::Requests::Glossary::List do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting a list of all glossaries' do
|
|
34
|
-
it 'returns a glossaries object' do
|
|
35
|
-
glossaries = glossary_list.request
|
|
36
|
-
expect(glossaries).to be_an(Array)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context 'when performing a bad request' do
|
|
41
|
-
context 'when using an invalid token' do
|
|
42
|
-
let(:api) do
|
|
43
|
-
api = build_deepl_api
|
|
44
|
-
api.configuration.auth_key = 'invalid'
|
|
45
|
-
api
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'raises an unauthorized error' do
|
|
49
|
-
expect { glossary_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
27
|
end
|
|
@@ -24,45 +24,4 @@ describe DeepL::Requests::Languages do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('languages') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting source languages' do
|
|
34
|
-
it 'returns a valid list of source languages' do
|
|
35
|
-
languages = languages_obj.request
|
|
36
|
-
|
|
37
|
-
expect(languages).to be_an(Array)
|
|
38
|
-
expect(languages.size).to eq(29)
|
|
39
|
-
expect(languages).to(be_any { |l| l.code == 'EN' && l.name == 'English' })
|
|
40
|
-
expect(languages).to(be_any { |l| l.code == 'ES' && l.name == 'Spanish' })
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'when requesting target languages' do
|
|
45
|
-
let(:options) { { type: :target } }
|
|
46
|
-
|
|
47
|
-
it 'returns a valid list of target languages' do
|
|
48
|
-
languages = languages_obj.request
|
|
49
|
-
|
|
50
|
-
expect(languages).to be_an(Array)
|
|
51
|
-
expect(languages.size).to eq(31)
|
|
52
|
-
expect(languages).not_to(be_any { |l| l.code == 'EN' && l.name == 'English' })
|
|
53
|
-
expect(languages).to(be_any { |l| l.code == 'ES' && l.name == 'Spanish' })
|
|
54
|
-
expect(languages)
|
|
55
|
-
.to(be_any { |l| l.code == 'EN-US' && l.name == 'English (American)' })
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'when using an invalid type' do
|
|
60
|
-
let(:options) { { type: :invalid } }
|
|
61
|
-
|
|
62
|
-
it 'returns an usage object' do
|
|
63
|
-
message = "Parameter 'type' is invalid. 'source' and 'target' are valid values."
|
|
64
|
-
expect { languages_obj.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
27
|
end
|
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
require 'spec_helper'
|
|
7
7
|
|
|
8
8
|
describe DeepL::Requests::Rephrase do
|
|
9
|
-
subject(:rephrase) { described_class.new(api, text, target_lang, writing_style, tone, options) }
|
|
10
|
-
|
|
11
9
|
around do |tests|
|
|
12
10
|
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
11
|
tests.call
|
|
@@ -19,153 +17,29 @@ describe DeepL::Requests::Rephrase do
|
|
|
19
17
|
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.'
|
|
20
18
|
end
|
|
21
19
|
let(:target_lang) { 'EN' }
|
|
22
|
-
let(:writing_style) { nil }
|
|
23
|
-
let(:tone) { nil }
|
|
24
|
-
let(:options) { {} }
|
|
25
|
-
|
|
26
|
-
describe '#request' do
|
|
27
|
-
around do |example|
|
|
28
|
-
VCR.use_cassette('rephrase_texts') { example.call }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'without a style or tone applied' do
|
|
32
|
-
context 'with a string as input' do
|
|
33
|
-
it 'returns a valid response as a DeepL Text resource' do
|
|
34
|
-
original_length = text.length
|
|
35
|
-
response_text = rephrase.request
|
|
36
|
-
|
|
37
|
-
expect(response_text).to be_a(DeepL::Resources::Text)
|
|
38
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
39
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context 'with an array of texts as input' do
|
|
44
|
-
let(:text) do
|
|
45
|
-
[
|
|
46
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
47
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
48
|
-
]
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'returns a valid response as an array of DeepL Text resources' do
|
|
52
|
-
response_texts = rephrase.request
|
|
53
|
-
|
|
54
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
55
|
-
response_texts.each_with_index do |response_text, index|
|
|
56
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
57
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'with a valid tone applied' do
|
|
64
|
-
let(:tone) { 'friendly' }
|
|
65
|
-
|
|
66
|
-
context 'with a string as input' do
|
|
67
|
-
it 'returns a valid response with a string as text input' do
|
|
68
|
-
original_length = text.length
|
|
69
|
-
response_text = rephrase.request
|
|
70
|
-
|
|
71
|
-
expect(response_text).to be_a(DeepL::Resources::Text)
|
|
72
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
73
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context 'with an array of texts as input' do
|
|
78
|
-
let(:text) do
|
|
79
|
-
[
|
|
80
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
81
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
82
|
-
]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'returns an array of valid text objects' do
|
|
86
|
-
response_texts = rephrase.request
|
|
87
|
-
|
|
88
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
89
|
-
response_texts.each_with_index do |response_text, index|
|
|
90
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
91
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context 'with a valid writing style applied' do
|
|
98
|
-
let(:writing_style) { 'business' }
|
|
99
20
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
107
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
108
|
-
end
|
|
21
|
+
describe '#initialize' do
|
|
22
|
+
context 'when passing additional headers' do
|
|
23
|
+
it 'merges the headers into the request headers' do
|
|
24
|
+
request = described_class.new(api, text, target_lang, nil, nil, {},
|
|
25
|
+
{ 'X-DeepL-Reporting-Tag' => 'my-tag' })
|
|
26
|
+
expect(request.send(:headers)).to include('X-DeepL-Reporting-Tag' => 'my-tag')
|
|
109
27
|
end
|
|
110
28
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
115
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
116
|
-
]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'returns an array of valid text objects' do
|
|
120
|
-
response_texts = rephrase.request
|
|
121
|
-
|
|
122
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
123
|
-
response_texts.each_with_index do |response_text, index|
|
|
124
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
125
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
126
|
-
end
|
|
127
|
-
end
|
|
29
|
+
it 'defaults to no additional headers' do
|
|
30
|
+
request = described_class.new(api, text, target_lang)
|
|
31
|
+
expect(request.send(:headers).keys).to contain_exactly('Authorization', 'User-Agent')
|
|
128
32
|
end
|
|
129
33
|
end
|
|
130
34
|
|
|
131
|
-
context 'with a writing style
|
|
35
|
+
context 'with a writing style and tone from the provided constants applied' do
|
|
132
36
|
let(:writing_style) { DeepL::Constants::WritingStyle::BUSINESS }
|
|
133
37
|
let(:tone) { DeepL::Constants::Tone::FRIENDLY }
|
|
134
38
|
|
|
135
39
|
it 'has the correct writing style and tone applied' do
|
|
136
|
-
|
|
137
|
-
expect(
|
|
138
|
-
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
context 'with an invalid writing style applied' do
|
|
142
|
-
let(:writing_style) { 'angry' }
|
|
143
|
-
|
|
144
|
-
it 'raises a bad request error' do
|
|
145
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
context 'when both writing style and tone are applied' do
|
|
150
|
-
let(:writing_style) { 'business' }
|
|
151
|
-
let(:tone) { 'friendly' }
|
|
152
|
-
|
|
153
|
-
it 'raises a bad request error' do
|
|
154
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
context 'when performing a bad request' do
|
|
159
|
-
context 'when using an invalid token' do
|
|
160
|
-
let(:api) do
|
|
161
|
-
api = build_deepl_api
|
|
162
|
-
api.configuration.auth_key = 'invalid'
|
|
163
|
-
api
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it 'raises an unauthorized error' do
|
|
167
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
168
|
-
end
|
|
40
|
+
request = described_class.new(api, text, target_lang, writing_style, tone)
|
|
41
|
+
expect(request.writing_style).to eq('business')
|
|
42
|
+
expect(request.tone).to eq('friendly')
|
|
169
43
|
end
|
|
170
44
|
end
|
|
171
45
|
end
|
|
@@ -27,28 +27,4 @@ describe DeepL::Requests::StyleRule::CreateCustomInstruction do
|
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
|
-
|
|
31
|
-
describe '#request' do
|
|
32
|
-
around do |example|
|
|
33
|
-
VCR.use_cassette('style_rules_crud') { example.call }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context 'when performing a valid request' do
|
|
37
|
-
subject(:create_instruction) do
|
|
38
|
-
described_class.new(api, new_rule.style_id, label, prompt)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
let(:new_rule) do
|
|
42
|
-
DeepL::Requests::StyleRule::Create.new(api, 'Instruction Test', 'en').request
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'returns a custom instruction object' do
|
|
46
|
-
instruction = create_instruction.request
|
|
47
|
-
expect(instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
48
|
-
expect(instruction.id).to be_a(String)
|
|
49
|
-
expect(instruction.label).to eq('Test Instruction')
|
|
50
|
-
expect(instruction.prompt).to eq('Always use formal language')
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
30
|
end
|
|
@@ -26,20 +26,4 @@ describe DeepL::Requests::StyleRule::Create do
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
|
-
|
|
30
|
-
describe '#request' do
|
|
31
|
-
around do |example|
|
|
32
|
-
VCR.use_cassette('style_rules_crud') { example.call }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
context 'when performing a valid request' do
|
|
36
|
-
it 'returns a style rule object' do
|
|
37
|
-
style_rule = create.request
|
|
38
|
-
expect(style_rule).to be_a(DeepL::Resources::StyleRule)
|
|
39
|
-
expect(style_rule.style_id).to be_a(String)
|
|
40
|
-
expect(style_rule.name).to eq('Test Style Rule')
|
|
41
|
-
expect(style_rule.language).to eq('en')
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
29
|
end
|
|
@@ -25,30 +25,4 @@ describe DeepL::Requests::StyleRule::DestroyCustomInstruction do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
|
|
29
|
-
describe '#request' do
|
|
30
|
-
around do |example|
|
|
31
|
-
VCR.use_cassette('style_rules_crud') { example.call }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when performing a valid request' do
|
|
35
|
-
subject(:destroy_instruction) do
|
|
36
|
-
described_class.new(api, new_rule.style_id, new_instruction.id)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
let(:new_rule) do
|
|
40
|
-
DeepL::Requests::StyleRule::Create.new(api, 'Destroy Instruction Test', 'en').request
|
|
41
|
-
end
|
|
42
|
-
let(:new_instruction) do
|
|
43
|
-
DeepL::Requests::StyleRule::CreateCustomInstruction.new(
|
|
44
|
-
api, new_rule.style_id, 'To Delete', 'Delete me'
|
|
45
|
-
).request
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'returns the deleted instruction id' do
|
|
49
|
-
response = destroy_instruction.request
|
|
50
|
-
expect(response).to eq(new_instruction.id)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
28
|
end
|