deepl-rb 3.10.0 → 4.0.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/.rubocop.yml +1 -1
- data/CHANGELOG.md +313 -1
- data/README.md +225 -309
- data/Rakefile +17 -8
- data/VERSION +1 -1
- data/deepl-rb.gemspec +73 -86
- data/lib/deepl/admin_client.rb +39 -14
- data/lib/deepl/api.rb +3 -17
- data/lib/deepl/app_info.rb +0 -1
- data/lib/deepl/client.rb +399 -84
- data/lib/deepl/configuration.rb +19 -70
- data/lib/deepl/exceptions/authorization_failed.rb +1 -1
- data/lib/deepl/exceptions/connection_error.rb +10 -7
- data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
- data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
- data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
- data/lib/deepl/exceptions/request_error.rb +7 -0
- data/lib/deepl/exceptions/server_error.rb +2 -1
- data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
- data/lib/deepl/exceptions/validation_error.rb +3 -2
- data/lib/deepl/requests/base.rb +129 -51
- data/lib/deepl/requests/correct.rb +2 -8
- data/lib/deepl/requests/document/upload.rb +29 -26
- data/lib/deepl/requests/glossary/base.rb +30 -0
- data/lib/deepl/requests/glossary/create.rb +18 -22
- data/lib/deepl/requests/glossary/destroy.rb +4 -16
- data/lib/deepl/requests/glossary/entries.rb +6 -14
- data/lib/deepl/requests/glossary/find.rb +3 -13
- data/lib/deepl/requests/glossary/language_pairs.rb +2 -2
- data/lib/deepl/requests/glossary/list.rb +2 -2
- data/lib/deepl/requests/languages.rb +6 -11
- data/lib/deepl/requests/languages_for_resource.rb +2 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +8 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +4 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +5 -3
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +22 -14
- data/lib/deepl/requests/rephrase.rb +3 -1
- data/lib/deepl/requests/spoken_terms/create.rb +5 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +1 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +1 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +9 -2
- data/lib/deepl/requests/style_profile/create.rb +5 -0
- data/lib/deepl/requests/style_profile/list.rb +2 -2
- data/lib/deepl/requests/style_rule/create.rb +25 -1
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +7 -0
- data/lib/deepl/requests/style_rule/helpers.rb +13 -4
- data/lib/deepl/requests/style_rule/list.rb +2 -0
- data/lib/deepl/requests/style_rule/update.rb +1 -0
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +2 -0
- data/lib/deepl/requests/translate.rb +20 -36
- data/lib/deepl/requests/translation_memory/create_export.rb +6 -1
- data/lib/deepl/requests/translation_memory/create_import.rb +10 -0
- data/lib/deepl/requests/translation_memory/download_export.rb +0 -4
- data/lib/deepl/requests/translation_memory/list.rb +2 -2
- data/lib/deepl/requests/translation_memory/segments.rb +2 -2
- data/lib/deepl/requests/translation_memory/storage_base.rb +5 -9
- data/lib/deepl/requests/write_improvements.rb +7 -0
- data/lib/deepl/resources/document_handle.rb +1 -26
- data/lib/deepl/resources/document_translation_status.rb +0 -12
- data/lib/deepl/resources/language.rb +4 -10
- data/lib/deepl/resources/multilingual_glossary.rb +4 -4
- data/lib/deepl/resources/style_rule.rb +1 -23
- data/lib/deepl/resources/translation_memory_job.rb +3 -4
- data/lib/deepl/resources/usage.rb +5 -38
- data/lib/deepl/utils/client_builder.rb +44 -9
- data/lib/deepl/utils/glossary_entries.rb +30 -0
- data/lib/deepl/utils/http_client_builder.rb +50 -13
- data/lib/deepl/utils/output_path.rb +25 -0
- data/lib/deepl/utils/term_validator.rb +3 -3
- data/lib/deepl/utils/translation_memory_operations.rb +230 -0
- data/lib/deepl.rb +6 -171
- data/lib/http_client_options.rb +2 -2
- data/lib/version.rb +1 -1
- data/upgrading_to_v4.md +374 -0
- metadata +9 -50
- data/.gitlab-ci.yml +0 -197
- data/lib/deepl/deprecation.rb +0 -42
- data/lib/deepl/document_api.rb +0 -150
- data/lib/deepl/exceptions/not_supported.rb +0 -20
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/style_rule_api.rb +0 -72
- data/lib/deepl/translation_memory_api.rb +0 -389
- data/license_checker.sh +0 -8
- data/spec/fixtures.rb +0 -33
- data/spec/offline/admin_client_spec.rb +0 -551
- data/spec/offline/client_spec.rb +0 -273
- data/spec/offline/configuration_spec.rb +0 -164
- data/spec/offline/constants_spec.rb +0 -180
- data/spec/offline/correct_text_spec.rb +0 -50
- data/spec/offline/deprecation_spec.rb +0 -32
- data/spec/offline/errors_spec.rb +0 -92
- data/spec/offline/glossaries_spec.rb +0 -98
- data/spec/offline/http_client_spec.rb +0 -319
- data/spec/offline/languages_spec.rb +0 -155
- data/spec/offline/module_methods_spec.rb +0 -13
- data/spec/offline/multilingual_glossaries_spec.rb +0 -358
- data/spec/offline/offline_helper.rb +0 -71
- data/spec/offline/rephrase_text_spec.rb +0 -73
- data/spec/offline/spoken_terms_spec.rb +0 -215
- data/spec/offline/style_profiles_spec.rb +0 -266
- data/spec/offline/style_rules_spec.rb +0 -318
- data/spec/offline/translate_document_spec.rb +0 -606
- data/spec/offline/translate_text_spec.rb +0 -286
- data/spec/offline/translation_memories_client_spec.rb +0 -256
- data/spec/offline/translation_memories_spec.rb +0 -463
- data/spec/offline/usage_spec.rb +0 -151
- data/spec/real_api/admin_client_spec.rb +0 -77
- data/spec/real_api/correct_text_spec.rb +0 -20
- data/spec/real_api/glossaries_spec.rb +0 -28
- data/spec/real_api/languages_spec.rb +0 -27
- data/spec/real_api/multilingual_glossaries_spec.rb +0 -53
- data/spec/real_api/proxy_spec.rb +0 -41
- data/spec/real_api/real_api_helper.rb +0 -65
- data/spec/real_api/rephrase_text_spec.rb +0 -16
- data/spec/real_api/spoken_terms_spec.rb +0 -56
- data/spec/real_api/style_profiles_spec.rb +0 -46
- data/spec/real_api/style_rules_spec.rb +0 -46
- data/spec/real_api/translate_document_spec.rb +0 -18
- data/spec/real_api/translate_text_spec.rb +0 -16
- data/spec/real_api/translation_memories_spec.rb +0 -56
- data/spec/real_api/usage_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -13
|
@@ -1,155 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
describe 'languages' do
|
|
9
|
-
describe 'DeepL.languages' do
|
|
10
|
-
let(:languages_reply) do
|
|
11
|
-
reply([
|
|
12
|
-
{ lang: 'en', name: 'English', usable_as_source: true, usable_as_target: false },
|
|
13
|
-
{ lang: 'en-gb', name: 'English (British)', usable_as_source: false,
|
|
14
|
-
usable_as_target: true, features: { formality: { status: 'stable' } } },
|
|
15
|
-
{ lang: 'de', name: 'German', usable_as_source: true, usable_as_target: true,
|
|
16
|
-
features: { formality: { status: 'stable' } } },
|
|
17
|
-
{ lang: 'ja', name: 'Japanese', usable_as_source: true, usable_as_target: true }
|
|
18
|
-
])
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def stub_languages
|
|
22
|
-
stub_request(:get, url('/v3/languages?resource=translate_text'))
|
|
23
|
-
.with(headers: json_headers).to_return(languages_reply)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it 'lists the source languages with upper-case codes by default' do
|
|
27
|
-
stub_languages
|
|
28
|
-
languages = DeepL.languages
|
|
29
|
-
|
|
30
|
-
expect(languages.map(&:code)).to eq(%w[EN DE JA])
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'lists the target languages with the formality support of each' do
|
|
34
|
-
stub_languages
|
|
35
|
-
languages = DeepL.languages(type: :target)
|
|
36
|
-
|
|
37
|
-
expect(languages.map { |l| [l.code, l.supports_formality?] })
|
|
38
|
-
.to eq([['EN-GB', true], ['DE', true], ['JA', false]])
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'accepts the type as a string' do
|
|
42
|
-
stub_languages
|
|
43
|
-
expect(DeepL.languages('type' => 'target').map(&:code)).to eq(%w[EN-GB DE JA])
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'raises NotSupported for the formality support of a source language' do
|
|
47
|
-
stub_languages
|
|
48
|
-
expect { DeepL.languages(type: :source).first.supports_formality? }
|
|
49
|
-
.to raise_error(DeepL::Exceptions::NotSupported, /only available on target languages/)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'raises ValidationError for an unknown type without sending a request' do
|
|
53
|
-
expect { DeepL.languages(type: :both) }
|
|
54
|
-
.to raise_error(DeepL::Exceptions::ValidationError, /Unsupported `type`/)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe DeepL::Client do
|
|
59
|
-
let(:client) { described_class.new('client-key', server_url: 'https://client.example.test') }
|
|
60
|
-
let(:client_headers) do
|
|
61
|
-
{ 'Authorization' => 'DeepL-Auth-Key client-key', 'Content-Type' => 'application/json' }
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def stub_client_get(path, body)
|
|
65
|
-
stub_request(:get, "https://client.example.test#{path}")
|
|
66
|
-
.with(headers: client_headers).to_return(reply(body))
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def stub_client_languages
|
|
70
|
-
stub_client_get('/v3/languages?resource=translate_text',
|
|
71
|
-
[{ lang: 'en', name: 'English', usable_as_source: true,
|
|
72
|
-
usable_as_target: false },
|
|
73
|
-
{ lang: 'en-gb', name: 'English (British)', usable_as_source: false,
|
|
74
|
-
usable_as_target: true, features: { formality: { status: 'stable' } } },
|
|
75
|
-
{ lang: 'ja', name: 'Japanese', usable_as_source: true,
|
|
76
|
-
usable_as_target: true }])
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it '#get_source_languages returns the source languages without formality support' do
|
|
80
|
-
stub_client_languages
|
|
81
|
-
|
|
82
|
-
languages = client.get_source_languages
|
|
83
|
-
|
|
84
|
-
expect(languages.map { |l| [l.code, l.name, l.supports_formality?] })
|
|
85
|
-
.to eq([['EN', 'English', nil], ['JA', 'Japanese', nil]])
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it '#get_target_languages returns the target languages with their formality support' do
|
|
89
|
-
stub_client_languages
|
|
90
|
-
|
|
91
|
-
languages = client.get_target_languages
|
|
92
|
-
|
|
93
|
-
expect(languages.map { |l| [l.code, l.supports_formality?] })
|
|
94
|
-
.to eq([['EN-GB', true], ['JA', false]])
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it '#get_language_resources parses the resource name and its features' do
|
|
98
|
-
stub_client_get('/v3/languages/resources',
|
|
99
|
-
[{ name: 'glossary', features: [{ name: 'formality' }] }])
|
|
100
|
-
|
|
101
|
-
resource = client.get_language_resources.first
|
|
102
|
-
|
|
103
|
-
expect([resource.name, resource.to_s, resource.supports?(:formality)])
|
|
104
|
-
.to eq(['glossary', 'glossary', true])
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
it '#get_languages_for_resource sends the resource and returns the codes unchanged' do
|
|
108
|
-
stub_client_get('/v3/languages?resource=translate_document',
|
|
109
|
-
[{ lang: 'en-GB', name: 'English (British)', status: 'stable',
|
|
110
|
-
usable_as_source: false, usable_as_target: true }])
|
|
111
|
-
|
|
112
|
-
languages = client.get_languages_for_resource(
|
|
113
|
-
DeepL::Constants::LanguageResourceName::TRANSLATE_DOCUMENT
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
expect(languages.map(&:code)).to eq(['en-GB'])
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it '#get_languages_for_resource sends one include parameter per value' do
|
|
120
|
-
# WebMock matches repeated query keys by their last value only, so the path of the sent
|
|
121
|
-
# request is asserted.
|
|
122
|
-
stub_client_get('/v3/languages?resource=voice&include=beta&include=external',
|
|
123
|
-
[{ lang: 'de', name: 'German' }])
|
|
124
|
-
|
|
125
|
-
languages = client.get_languages_for_resource(
|
|
126
|
-
:voice, include: [DeepL::Constants::LanguageInclude::BETA,
|
|
127
|
-
DeepL::Constants::LanguageInclude::EXTERNAL]
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
expect(languages.first.request.path)
|
|
131
|
-
.to eq('/v3/languages?resource=voice&include=beta&include=external')
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it '#get_languages_for_resource sends a resource and include value without a constant' do
|
|
135
|
-
stub_client_get('/v3/languages?resource=new_resource&include=preview', [])
|
|
136
|
-
|
|
137
|
-
client.get_languages_for_resource('new_resource', include: 'preview')
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe 'DeepL.glossaries.language_pairs' do
|
|
142
|
-
it 'requests the glossary languages and pairs every source with every other target' do
|
|
143
|
-
stub_request(:get,
|
|
144
|
-
url('/v3/languages?resource=glossary')).with(headers: json_headers).to_return(
|
|
145
|
-
reply([{ lang: 'en', usable_as_source: true, usable_as_target: true },
|
|
146
|
-
{ lang: 'de', usable_as_source: true, usable_as_target: true },
|
|
147
|
-
{ lang: 'fr', usable_as_source: false, usable_as_target: true }])
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
pairs = DeepL.glossaries.language_pairs
|
|
151
|
-
|
|
152
|
-
expect(pairs.map(&:to_s)).to eq(['en - de', 'en - fr', 'de - en', 'de - fr'])
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL do
|
|
9
|
-
it 'has no module-level methods for the operations added after 3.9.0' do
|
|
10
|
-
expect(%i[correct language_resources languages_for_resource multilingual_glossaries]
|
|
11
|
-
.map { |name| described_class.respond_to?(name) }).to eq([false] * 4)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,358 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
describe 'multilingual glossaries' do
|
|
9
|
-
# The client has its own key and server, different from the module configuration, so a request
|
|
10
|
-
# that falls back to module state hits no stub.
|
|
11
|
-
describe 'DeepL::Client' do
|
|
12
|
-
let(:client) { DeepL::Client.new('client-key', server_url: 'https://client.example.test') }
|
|
13
|
-
let(:glossary_json) do
|
|
14
|
-
{ glossary_id: 'g-1', name: 'terms', creation_time: '2026-10-23T17:15:53.434769Z',
|
|
15
|
-
dictionaries: [{ source_lang: 'en', target_lang: 'de', entry_count: 2 }] }
|
|
16
|
-
end
|
|
17
|
-
let(:dictionary_json) { { source_lang: 'en', target_lang: 'de', entry_count: 1 } }
|
|
18
|
-
let(:apple) do
|
|
19
|
-
DeepL::Resources::MultilingualGlossaryDictionaryEntries.new('EN', 'DE', [%w[Apple Apfel]])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def url(path)
|
|
23
|
-
"https://client.example.test#{path}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def json_headers
|
|
27
|
-
{ 'Authorization' => 'DeepL-Auth-Key client-key', 'Content-Type' => 'application/json' }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def auth_headers
|
|
31
|
-
{ 'Authorization' => 'DeepL-Auth-Key client-key' }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def no_body
|
|
35
|
-
->(body) { body.to_s.empty? }
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def glossary
|
|
39
|
-
stub_request(:get, url('/v3/glossaries/g-1')).to_return(reply(glossary_json))
|
|
40
|
-
client.get_multilingual_glossary('g-1')
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe '#create_multilingual_glossary' do
|
|
44
|
-
it 'takes MultilingualGlossaryDictionaryEntries objects and sends them as TSV' do
|
|
45
|
-
stub_request(:post, url('/v3/glossaries')).with(
|
|
46
|
-
body: { name: 'terms', dictionaries: [{ source_lang: 'EN', target_lang: 'DE',
|
|
47
|
-
entries: "Apple\tApfel", entries_format: 'tsv' }],
|
|
48
|
-
beta: true },
|
|
49
|
-
headers: json_headers
|
|
50
|
-
).to_return(reply(glossary_json, 201))
|
|
51
|
-
|
|
52
|
-
client.create_multilingual_glossary('terms', [apple], extra_body_parameters: { beta: true })
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'trims the terms of MultilingualGlossaryDictionaryEntries given as a TSV string' do
|
|
56
|
-
dictionary = { source_lang: 'EN', target_lang: 'DE', entries: "Apple\tApfel",
|
|
57
|
-
entries_format: 'tsv' }
|
|
58
|
-
stub_request(:post, url('/v3/glossaries'))
|
|
59
|
-
.with(body: { name: 'terms', dictionaries: [dictionary] })
|
|
60
|
-
.to_return(reply(glossary_json, 201))
|
|
61
|
-
entries_class = DeepL::Resources::MultilingualGlossaryDictionaryEntries
|
|
62
|
-
entries = entries_class.new('EN', 'DE', "Apple \tApfel\n")
|
|
63
|
-
|
|
64
|
-
client.create_multilingual_glossary('terms', [entries])
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
it 'accepts dictionaries with string keys and a string of entries' do
|
|
68
|
-
stub_request(:post, url('/v3/glossaries')).with(
|
|
69
|
-
body: { name: 'terms',
|
|
70
|
-
dictionaries: [{ source_lang: 'EN', target_lang: 'FR', entries: "a\tb",
|
|
71
|
-
entries_format: 'tsv' }] }
|
|
72
|
-
).to_return(reply(glossary_json, 201))
|
|
73
|
-
|
|
74
|
-
client.create_multilingual_glossary(
|
|
75
|
-
'terms', [{ 'source_lang' => 'EN', 'target_lang' => 'FR', 'entries' => "a\tb" }]
|
|
76
|
-
)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
it 'trims the terms of a TSV string of entries and skips blank lines' do
|
|
80
|
-
stub_request(:post, url('/v3/glossaries')).with(
|
|
81
|
-
body: { name: 'terms',
|
|
82
|
-
dictionaries: [{ source_lang: 'EN', target_lang: 'DE',
|
|
83
|
-
entries: "Apple\tApfel\nBanana\tBanane",
|
|
84
|
-
entries_format: 'tsv' }] }
|
|
85
|
-
).to_return(reply(glossary_json, 201))
|
|
86
|
-
|
|
87
|
-
client.create_multilingual_glossary(
|
|
88
|
-
'terms', [{ source_lang: 'EN', target_lang: 'DE',
|
|
89
|
-
entries: " Apple \t Apfel\r\n\n Banana\tBanane \n" }]
|
|
90
|
-
)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
[[%W[Apple\tPie Apfel]], [%W[Apple Apfel\nKuchen]], "Apple\tApfel\tKuchen", "Apple\n",
|
|
94
|
-
" \tApfel", "Apple\tAp\u0001fel", "Apple\tAp\u2028fel"].each do |entries|
|
|
95
|
-
it "raises ValidationError for #{entries.inspect} and sends no request" do
|
|
96
|
-
dictionaries = [{ source_lang: 'EN', target_lang: 'DE', entries: entries }]
|
|
97
|
-
|
|
98
|
-
expect { client.create_multilingual_glossary('terms', dictionaries) }
|
|
99
|
-
.to raise_error(DeepL::Exceptions::ValidationError)
|
|
100
|
-
expect(a_request(:any, /.*/)).not_to have_been_made
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
{ 'a duplicate source term' => [%w[Apple Apfel], [' Apple', 'Apfel2']],
|
|
105
|
-
'a one-element pair' => [['Apple']] }.each do |label, pairs|
|
|
106
|
-
it "raises ValidationError for #{label} and sends no request" do
|
|
107
|
-
entries_class = DeepL::Resources::MultilingualGlossaryDictionaryEntries
|
|
108
|
-
|
|
109
|
-
expect do
|
|
110
|
-
client.create_multilingual_glossary('terms', [entries_class.new('EN', 'DE', pairs)])
|
|
111
|
-
end.to raise_error(DeepL::Exceptions::ValidationError, /Apple/)
|
|
112
|
-
expect(a_request(:any, /.*/)).not_to have_been_made
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it 'parses the creation time as a UTC Time' do
|
|
117
|
-
stub_request(:post, url('/v3/glossaries')).to_return(reply(glossary_json, 201))
|
|
118
|
-
|
|
119
|
-
created = client.create_multilingual_glossary('terms', [])
|
|
120
|
-
|
|
121
|
-
expect(created.creation_time)
|
|
122
|
-
.to eq(Time.utc(2026, 10, 23, 17, 15, Rational(53_434_769, 1_000_000)))
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
describe '#create_multilingual_glossary_from_csv' do
|
|
127
|
-
it 'sends the CSV content of a string or an IO with the csv entries format' do
|
|
128
|
-
body = { name: 'terms', dictionaries: [{ source_lang: 'EN', target_lang: 'DE',
|
|
129
|
-
entries: "a,b\n", entries_format: 'csv' }] }
|
|
130
|
-
stub_request(:post, url('/v3/glossaries')).with(body: body)
|
|
131
|
-
.to_return(reply(glossary_json, 201))
|
|
132
|
-
|
|
133
|
-
client.create_multilingual_glossary_from_csv('terms', 'EN', 'DE', "a,b\n")
|
|
134
|
-
client.create_multilingual_glossary_from_csv('terms', 'EN', 'DE', StringIO.new("a,b\n"))
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
describe '#list_multilingual_glossaries and #get_multilingual_glossary' do
|
|
139
|
-
it 'send GET requests and take a glossary object' do
|
|
140
|
-
stub_request(:get, url('/v3/glossaries')).with(headers: auth_headers)
|
|
141
|
-
.to_return(reply(glossaries: [glossary_json]))
|
|
142
|
-
|
|
143
|
-
expect(client.list_multilingual_glossaries.map(&:id)).to eq(['g-1'])
|
|
144
|
-
expect(client.get_multilingual_glossary(glossary).name).to eq('terms')
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
describe '#update_multilingual_glossary' do
|
|
149
|
-
it 'sends the name and the dictionaries' do
|
|
150
|
-
stub_request(:patch, url('/v3/glossaries/g-1')).with(
|
|
151
|
-
body: { name: 'new', dictionaries: [{ source_lang: 'EN', target_lang: 'FR',
|
|
152
|
-
entries: "a\tb", entries_format: 'tsv' }] },
|
|
153
|
-
headers: json_headers
|
|
154
|
-
).to_return(reply(glossary_json))
|
|
155
|
-
|
|
156
|
-
client.update_multilingual_glossary(
|
|
157
|
-
'g-1', name: 'new', dictionaries: [{ source_lang: 'EN', target_lang: 'FR',
|
|
158
|
-
entries: [%w[a b]] }]
|
|
159
|
-
)
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
it 'sends an empty object when no argument is given' do
|
|
163
|
-
stub_request(:patch, url('/v3/glossaries/g-1')).with(body: '{}')
|
|
164
|
-
.to_return(reply(glossary_json))
|
|
165
|
-
|
|
166
|
-
client.update_multilingual_glossary('g-1')
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
describe '#update_multilingual_glossary_name and #update_multilingual_glossary_dictionary' do
|
|
171
|
-
it 'send a PATCH with only the name or only the dictionary' do
|
|
172
|
-
stub_request(:patch, url('/v3/glossaries/g-1')).with(body: { name: 'new' })
|
|
173
|
-
.to_return(reply(glossary_json))
|
|
174
|
-
stub_request(:patch, url('/v3/glossaries/g-1')).with(
|
|
175
|
-
body: { dictionaries: [{ source_lang: 'EN', target_lang: 'DE', entries: "Apple\tApfel",
|
|
176
|
-
entries_format: 'tsv' }] }
|
|
177
|
-
).to_return(reply(glossary_json))
|
|
178
|
-
|
|
179
|
-
client.update_multilingual_glossary_name(glossary, 'new')
|
|
180
|
-
client.update_multilingual_glossary_dictionary(glossary, apple)
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it 'sends CSV content with the csv entries format' do
|
|
184
|
-
stub_request(:patch, url('/v3/glossaries/g-1')).with(
|
|
185
|
-
body: { dictionaries: [{ source_lang: 'EN', target_lang: 'DE', entries: "a,b\n",
|
|
186
|
-
entries_format: 'csv' }] }
|
|
187
|
-
).to_return(reply(glossary_json))
|
|
188
|
-
|
|
189
|
-
client.update_multilingual_glossary_dictionary_from_csv('g-1', 'EN', 'DE', "a,b\n")
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
describe '#replace_multilingual_glossary_dictionary' do
|
|
194
|
-
it 'sends a PUT with one dictionary given as a hash' do
|
|
195
|
-
stub_request(:put, url('/v3/glossaries/g-1/dictionaries')).with(
|
|
196
|
-
body: { source_lang: 'EN', target_lang: 'DE', entries: "a\tb", entries_format: 'tsv' },
|
|
197
|
-
headers: json_headers
|
|
198
|
-
).to_return(reply(dictionary_json))
|
|
199
|
-
|
|
200
|
-
replaced = client.replace_multilingual_glossary_dictionary(
|
|
201
|
-
'g-1', { source_lang: 'EN', target_lang: 'DE', entries: [%w[a b]] }
|
|
202
|
-
)
|
|
203
|
-
|
|
204
|
-
expect([replaced.source_lang, replaced.target_lang, replaced.entry_count])
|
|
205
|
-
.to eq(['en', 'de', 1])
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
it 'sends CSV content with the csv entries format' do
|
|
209
|
-
stub_request(:put, url('/v3/glossaries/g-1/dictionaries')).with(
|
|
210
|
-
body: { source_lang: 'EN', target_lang: 'DE', entries: "a,b\n", entries_format: 'csv' }
|
|
211
|
-
).to_return(reply(dictionary_json))
|
|
212
|
-
|
|
213
|
-
client.replace_multilingual_glossary_dictionary_from_csv('g-1', 'EN', 'DE', "a,b\n")
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
describe 'entries_format with converted entries' do
|
|
218
|
-
operations = {
|
|
219
|
-
'create' => [:post, '/v3/glossaries', lambda { |client, dictionary|
|
|
220
|
-
client.create_multilingual_glossary('terms', [dictionary])
|
|
221
|
-
}, ->(sent) { { name: 'terms', dictionaries: [sent] } }],
|
|
222
|
-
'update' => [:patch, '/v3/glossaries/g-1', lambda { |client, dictionary|
|
|
223
|
-
client.update_multilingual_glossary('g-1', dictionaries: [dictionary])
|
|
224
|
-
}, ->(sent) { { dictionaries: [sent] } }],
|
|
225
|
-
'replace' => [:put, '/v3/glossaries/g-1/dictionaries', lambda { |client, dictionary|
|
|
226
|
-
client.replace_multilingual_glossary_dictionary('g-1', dictionary)
|
|
227
|
-
}, ->(sent) { sent }]
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
operations.each do |name, (method, path, call, body)|
|
|
231
|
-
{ 'a hash' => { 'Hello' => 'Hallo' }, 'pairs' => [%w[Hello Hallo]] }.each do |kind, entries|
|
|
232
|
-
it "#{name} sends #{kind} given with entries_format csv as TSV" do
|
|
233
|
-
sent = { source_lang: 'en', target_lang: 'de', entries: "Hello\tHallo",
|
|
234
|
-
entries_format: 'tsv' }
|
|
235
|
-
stub = stub_request(method, url(path)).with(body: body.call(sent))
|
|
236
|
-
.to_return(reply(glossary_json))
|
|
237
|
-
|
|
238
|
-
call.call(client, { source_lang: 'en', target_lang: 'de', entries: entries,
|
|
239
|
-
entries_format: 'csv' })
|
|
240
|
-
|
|
241
|
-
expect(stub).to have_been_requested
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
it "#{name} sends a CSV string given with entries_format csv unchanged" do
|
|
246
|
-
sent = { source_lang: 'en', target_lang: 'de', entries: "Hello,Hallo\n",
|
|
247
|
-
entries_format: 'csv' }
|
|
248
|
-
stub = stub_request(method, url(path)).with(body: body.call(sent))
|
|
249
|
-
.to_return(reply(glossary_json))
|
|
250
|
-
|
|
251
|
-
call.call(client, sent)
|
|
252
|
-
|
|
253
|
-
expect(stub).to have_been_requested
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
describe '#get_multilingual_glossary_dictionary_entries' do
|
|
259
|
-
it 'encodes a space in a query value as %20' do
|
|
260
|
-
expect(Net::HTTP::Get).to receive(:new)
|
|
261
|
-
.with('/v3/glossaries/g-1/entries?source_lang=E%20N&target_lang=DE', anything)
|
|
262
|
-
.and_call_original
|
|
263
|
-
stub_request(:get, url('/v3/glossaries/g-1/entries?source_lang=E%20N&target_lang=DE'))
|
|
264
|
-
.to_return(reply(dictionaries: [{ source_lang: 'en', target_lang: 'de', entries: '',
|
|
265
|
-
entries_format: 'tsv' }]))
|
|
266
|
-
|
|
267
|
-
client.get_multilingual_glossary_dictionary_entries('g-1', 'E N', 'DE')
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
it 'returns the one dictionary with its entries as a hash' do
|
|
271
|
-
stub_request(:get, url('/v3/glossaries/g-1/entries?source_lang=EN&target_lang=DE'))
|
|
272
|
-
.with(headers: json_headers)
|
|
273
|
-
.to_return(reply(dictionaries: [{ source_lang: 'en', target_lang: 'de',
|
|
274
|
-
entries: "Apple\tApfel\nBanana\tBanane\n",
|
|
275
|
-
entries_format: 'tsv' }]))
|
|
276
|
-
|
|
277
|
-
result = client.get_multilingual_glossary_dictionary_entries('g-1', 'EN', 'DE')
|
|
278
|
-
|
|
279
|
-
expect([result.source_lang, result.target_lang, result.entries])
|
|
280
|
-
.to eq(['en', 'de', { 'Apple' => 'Apfel', 'Banana' => 'Banane' }])
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
it 'returns entries that update and replace send back as TSV' do # rubocop:disable RSpec/ExampleLength
|
|
284
|
-
stub_request(:get, url('/v3/glossaries/g-1/entries?source_lang=EN&target_lang=DE'))
|
|
285
|
-
.to_return(reply(dictionaries: [{ source_lang: 'en', target_lang: 'de',
|
|
286
|
-
entries: "Hello\tHallo", entries_format: 'tsv' }]))
|
|
287
|
-
dictionary = { source_lang: 'en', target_lang: 'de', entries: "Hello\tHallo",
|
|
288
|
-
entries_format: 'tsv' }
|
|
289
|
-
stub_request(:patch, url('/v3/glossaries/g-1'))
|
|
290
|
-
.with(body: { dictionaries: [dictionary] }).to_return(reply(glossary_json))
|
|
291
|
-
stub_request(:put, url('/v3/glossaries/g-1/dictionaries'))
|
|
292
|
-
.with(body: dictionary).to_return(reply(dictionary_json))
|
|
293
|
-
|
|
294
|
-
entries = client.get_multilingual_glossary_dictionary_entries('g-1', 'EN', 'DE')
|
|
295
|
-
client.update_multilingual_glossary_dictionary('g-1', entries)
|
|
296
|
-
client.replace_multilingual_glossary_dictionary('g-1', entries)
|
|
297
|
-
expect(entries.entries).to eq('Hello' => 'Hallo')
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
it 'raises NotFound when the glossary has no dictionary for the language pair' do
|
|
301
|
-
stub_request(:get, url('/v3/glossaries/g-1/entries?source_lang=EN&target_lang=JA'))
|
|
302
|
-
.to_return(reply(dictionaries: []))
|
|
303
|
-
|
|
304
|
-
expect { client.get_multilingual_glossary_dictionary_entries('g-1', 'EN', 'JA') }
|
|
305
|
-
.to raise_error(DeepL::Exceptions::NotFound, /no dictionary for EN -> JA/)
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
it 'returns entries that can be sent to another glossary' do
|
|
309
|
-
stub_request(:get, url('/v3/glossaries/g-1/entries?source_lang=EN&target_lang=DE'))
|
|
310
|
-
.to_return(reply(dictionaries: [{ source_lang: 'en', target_lang: 'de',
|
|
311
|
-
entries: "a\tb", entries_format: 'tsv' }]))
|
|
312
|
-
stub_request(:post, url('/v3/glossaries')).with(
|
|
313
|
-
body: { name: 'copy', dictionaries: [{ source_lang: 'en', target_lang: 'de',
|
|
314
|
-
entries: "a\tb", entries_format: 'tsv' }] }
|
|
315
|
-
).to_return(reply(glossary_json, 201))
|
|
316
|
-
|
|
317
|
-
entries = client.get_multilingual_glossary_dictionary_entries('g-1', 'EN', 'DE')
|
|
318
|
-
client.create_multilingual_glossary('copy', [entries])
|
|
319
|
-
end
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
describe '#delete_multilingual_glossary_dictionary and #delete_multilingual_glossary' do
|
|
323
|
-
it 'send DELETE requests and return nil' do
|
|
324
|
-
stub_request(:delete, url('/v3/glossaries/g-1/dictionaries?source_lang=EN&target_lang=FR'))
|
|
325
|
-
.with(headers: json_headers, body: no_body).to_return(status: 204)
|
|
326
|
-
stub_request(:delete, url('/v3/glossaries/g-1')).with(headers: auth_headers)
|
|
327
|
-
.to_return(status: 204)
|
|
328
|
-
|
|
329
|
-
expect(client.delete_multilingual_glossary_dictionary(glossary, 'EN', 'FR')).to be_nil
|
|
330
|
-
expect(client.delete_multilingual_glossary(glossary)).to be_nil
|
|
331
|
-
end
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
describe 'glossary IDs' do
|
|
335
|
-
before do
|
|
336
|
-
encoded = url('/v3/glossaries/a%20b%2Fc')
|
|
337
|
-
stub_request(:get, encoded).to_return(reply(glossary_json))
|
|
338
|
-
stub_request(:patch, encoded).to_return(reply(glossary_json))
|
|
339
|
-
stub_request(:delete, encoded).to_return(status: 204)
|
|
340
|
-
stub_request(:get, "#{encoded}/entries?source_lang=EN&target_lang=DE")
|
|
341
|
-
.to_return(reply(dictionaries: [{ source_lang: 'en', target_lang: 'de', entries: '' }]))
|
|
342
|
-
stub_request(:put, "#{encoded}/dictionaries").to_return(reply(dictionary_json))
|
|
343
|
-
stub_request(:delete, "#{encoded}/dictionaries?source_lang=EN&target_lang=DE")
|
|
344
|
-
.to_return(status: 204)
|
|
345
|
-
end
|
|
346
|
-
|
|
347
|
-
it 'are URL-encoded in every path' do
|
|
348
|
-
id = 'a b/c'
|
|
349
|
-
client.get_multilingual_glossary(id)
|
|
350
|
-
client.update_multilingual_glossary_name(id, 'x')
|
|
351
|
-
client.delete_multilingual_glossary(id)
|
|
352
|
-
client.get_multilingual_glossary_dictionary_entries(id, 'EN', 'DE')
|
|
353
|
-
client.replace_multilingual_glossary_dictionary(id, apple)
|
|
354
|
-
client.delete_multilingual_glossary_dictionary(id, 'EN', 'DE')
|
|
355
|
-
end
|
|
356
|
-
end
|
|
357
|
-
end
|
|
358
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
if defined?(RealApiHelper)
|
|
7
|
-
raise 'spec/offline and spec/real_api cannot run in one process: WebMock blocks the network'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
require_relative '../spec_helper'
|
|
11
|
-
require_relative '../fixtures'
|
|
12
|
-
require 'webmock/rspec'
|
|
13
|
-
|
|
14
|
-
# The offline suite never touches the network: every request is declared with WebMock and
|
|
15
|
-
# asserted exactly.
|
|
16
|
-
WebMock.disable_net_connect!
|
|
17
|
-
|
|
18
|
-
module OfflineHelper
|
|
19
|
-
HOST = 'https://api.deepl.com'
|
|
20
|
-
AUTH_KEY = 'k'
|
|
21
|
-
|
|
22
|
-
def url(path)
|
|
23
|
-
"#{HOST}#{path}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Headers of a request with a JSON Content-Type.
|
|
27
|
-
def json_headers
|
|
28
|
-
{ 'Authorization' => "DeepL-Auth-Key #{AUTH_KEY}", 'Content-Type' => 'application/json' }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# Headers of a request without a body.
|
|
32
|
-
def auth_headers
|
|
33
|
-
{ 'Authorization' => "DeepL-Auth-Key #{AUTH_KEY}" }
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# True for a request sent without a body and without a Content-Type, as GET and DELETE are.
|
|
37
|
-
def bodyless?(request)
|
|
38
|
-
request.body.to_s.empty? && !request.headers.key?('Content-Type')
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def reply(body = {}, status = 200)
|
|
42
|
-
{ status: status, body: body.is_a?(String) ? body : body.to_json }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def usage_reply
|
|
46
|
-
reply(character_count: 1, character_limit: 10)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
RSpec.configure do |config|
|
|
51
|
-
config.include OfflineHelper
|
|
52
|
-
config.include Fixtures
|
|
53
|
-
|
|
54
|
-
config.before do
|
|
55
|
-
DeepL.configure do |c|
|
|
56
|
-
c.auth_key = OfflineHelper::AUTH_KEY
|
|
57
|
-
c.host = OfflineHelper::HOST
|
|
58
|
-
c.logger = nil
|
|
59
|
-
c.max_doc_status_queries = nil
|
|
60
|
-
c.headers = {}
|
|
61
|
-
# The default of 5 retries would sleep for about 16 seconds in every retry example.
|
|
62
|
-
c.max_network_retries = 2
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# A declared request that the SDK never sent is a failure. webmock/rspec resets the stubs
|
|
67
|
-
# in an around hook, which runs after this one.
|
|
68
|
-
config.after do
|
|
69
|
-
expect(WebMock::StubRegistry.instance.request_stubs).to all(have_been_requested.at_least_once)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
@@ -1,73 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
describe 'DeepL.rephrase' do
|
|
9
|
-
def stub_rephrase(body = nil)
|
|
10
|
-
request = stub_request(:post, url('/v2/write/rephrase'))
|
|
11
|
-
request = request.with(body: body, headers: json_headers) unless body.nil?
|
|
12
|
-
request
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'sends only the text when no other argument is given' do
|
|
16
|
-
stub_rephrase(text: ['Hello']).to_return(reply(improvements: [{ text: 'Hi' }]))
|
|
17
|
-
DeepL.rephrase('Hello')
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it 'sends the target language, writing style and tone' do
|
|
21
|
-
stub_rephrase(text: %w[a b], target_lang: 'en-GB', writing_style: 'business',
|
|
22
|
-
tone: 'diplomatic')
|
|
23
|
-
.to_return(reply(improvements: [{ text: 'x' }, { text: 'y' }]))
|
|
24
|
-
|
|
25
|
-
DeepL.rephrase(%w[a b], 'en-GB', 'business', 'diplomatic')
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'sends the additional headers' do
|
|
29
|
-
stub_request(:post, url('/v2/write/rephrase'))
|
|
30
|
-
.with(headers: { 'X-DeepL-Reporting-Tag' => 'tag' })
|
|
31
|
-
.to_return(reply(improvements: [{ text: 'Hi' }]))
|
|
32
|
-
|
|
33
|
-
DeepL.rephrase('Hello', nil, nil, nil, {}, { 'X-DeepL-Reporting-Tag' => 'tag' })
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'overrides built-in parameters with extra_body_parameters' do
|
|
37
|
-
stub_rephrase(text: ['Hello'], target_lang: 'de', beta: true)
|
|
38
|
-
.to_return(reply(improvements: [{ text: 'Hallo' }]))
|
|
39
|
-
|
|
40
|
-
DeepL.rephrase('Hello', 'en', nil, nil,
|
|
41
|
-
extra_body_parameters: { target_lang: 'de', beta: true })
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'returns a text for a string' do
|
|
45
|
-
stub_rephrase.to_return(reply(improvements: [{ text: 'Hi' }]))
|
|
46
|
-
|
|
47
|
-
expect(DeepL.rephrase('Hello')).to be_a(DeepL::Resources::Text)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'parses the target language of each improvement' do
|
|
51
|
-
stub_rephrase.to_return(reply(improvements: [
|
|
52
|
-
{ text: 'x', detected_source_language: 'en',
|
|
53
|
-
target_language: 'en-GB' }, { text: 'y', target_language: 1 }
|
|
54
|
-
]))
|
|
55
|
-
|
|
56
|
-
expect(DeepL.rephrase(%w[a b]).map(&:target_language)).to eq(['en-GB', nil])
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'returns an array of texts for an array' do
|
|
60
|
-
stub_rephrase.to_return(reply(improvements: [{ text: 'x' }, { text: 'y' }]))
|
|
61
|
-
|
|
62
|
-
expect(DeepL.rephrase(%w[a b]).map(&:class)).to eq([DeepL::Resources::Text] * 2)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
[['Hello', []], [%w[a b], [{ text: 'x' }]]].each do |text, improvements|
|
|
66
|
-
it "raises DeepL::Exceptions::Error for #{improvements.size} improvements of #{text.inspect}" do
|
|
67
|
-
stub_rephrase.to_return(reply(improvements: improvements))
|
|
68
|
-
|
|
69
|
-
expect { DeepL.rephrase(text) }
|
|
70
|
-
.to raise_error(an_instance_of(DeepL::Exceptions::Error), /expected \d improvements/)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|