deepl-rb 3.3.0 → 3.5.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.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -2
  3. data/README.md +72 -0
  4. metadata +2 -95
  5. data/.circleci/config.yml +0 -27
  6. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  7. data/.gitlab-ci.yml +0 -172
  8. data/.rubocop.yml +0 -51
  9. data/CODE_OF_CONDUCT.md +0 -132
  10. data/CONTRIBUTING.md +0 -37
  11. data/Gemfile +0 -24
  12. data/Rakefile +0 -54
  13. data/SECURITY.md +0 -58
  14. data/VERSION +0 -1
  15. data/deepl-rb.gemspec +0 -133
  16. data/lib/deepl/api.rb +0 -22
  17. data/lib/deepl/configuration.rb +0 -59
  18. data/lib/deepl/constants/base_constant.rb +0 -18
  19. data/lib/deepl/constants/formality.rb +0 -16
  20. data/lib/deepl/constants/model_type.rb +0 -14
  21. data/lib/deepl/constants/split_sentences.rb +0 -14
  22. data/lib/deepl/constants/tag_handling.rb +0 -13
  23. data/lib/deepl/constants/tone.rb +0 -20
  24. data/lib/deepl/constants/writing_style.rb +0 -20
  25. data/lib/deepl/document_api.rb +0 -121
  26. data/lib/deepl/exceptions/authorization_failed.rb +0 -14
  27. data/lib/deepl/exceptions/bad_request.rb +0 -16
  28. data/lib/deepl/exceptions/document_translation_error.rb +0 -15
  29. data/lib/deepl/exceptions/error.rb +0 -14
  30. data/lib/deepl/exceptions/limit_exceeded.rb +0 -18
  31. data/lib/deepl/exceptions/not_found.rb +0 -16
  32. data/lib/deepl/exceptions/not_supported.rb +0 -14
  33. data/lib/deepl/exceptions/quota_exceeded.rb +0 -14
  34. data/lib/deepl/exceptions/request_entity_too_large.rb +0 -15
  35. data/lib/deepl/exceptions/request_error.rb +0 -21
  36. data/lib/deepl/exceptions/server_error.rb +0 -18
  37. data/lib/deepl/glossary_api.rb +0 -38
  38. data/lib/deepl/requests/base.rb +0 -196
  39. data/lib/deepl/requests/document/download.rb +0 -44
  40. data/lib/deepl/requests/document/get_status.rb +0 -44
  41. data/lib/deepl/requests/document/upload.rb +0 -74
  42. data/lib/deepl/requests/glossary/create.rb +0 -59
  43. data/lib/deepl/requests/glossary/destroy.rb +0 -37
  44. data/lib/deepl/requests/glossary/entries.rb +0 -37
  45. data/lib/deepl/requests/glossary/find.rb +0 -38
  46. data/lib/deepl/requests/glossary/language_pairs.rb +0 -38
  47. data/lib/deepl/requests/glossary/list.rb +0 -37
  48. data/lib/deepl/requests/languages.rb +0 -37
  49. data/lib/deepl/requests/rephrase.rb +0 -55
  50. data/lib/deepl/requests/translate.rb +0 -82
  51. data/lib/deepl/requests/usage.rb +0 -33
  52. data/lib/deepl/resources/base.rb +0 -17
  53. data/lib/deepl/resources/document_handle.rb +0 -57
  54. data/lib/deepl/resources/document_translation_status.rb +0 -54
  55. data/lib/deepl/resources/glossary.rb +0 -28
  56. data/lib/deepl/resources/language.rb +0 -30
  57. data/lib/deepl/resources/language_pair.rb +0 -23
  58. data/lib/deepl/resources/text.rb +0 -24
  59. data/lib/deepl/resources/usage.rb +0 -27
  60. data/lib/deepl/utils/backoff_timer.rb +0 -46
  61. data/lib/deepl/utils/exception_builder.rb +0 -34
  62. data/lib/deepl.rb +0 -147
  63. data/lib/http_client_options.rb +0 -22
  64. data/spec/api/api_spec.rb +0 -20
  65. data/spec/api/configuration_spec.rb +0 -122
  66. data/spec/api/deepl_spec.rb +0 -460
  67. data/spec/constants/constants_spec.rb +0 -158
  68. data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
  69. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
  70. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
  71. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
  72. data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
  73. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
  74. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
  75. data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
  76. data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
  77. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
  78. data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10415
  79. data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
  80. data/spec/integration_tests/document_api_spec.rb +0 -177
  81. data/spec/integration_tests/integration_test_utils.rb +0 -170
  82. data/spec/requests/glossary/create_spec.rb +0 -65
  83. data/spec/requests/glossary/destroy_spec.rb +0 -66
  84. data/spec/requests/glossary/entries_spec.rb +0 -62
  85. data/spec/requests/glossary/find_spec.rb +0 -68
  86. data/spec/requests/glossary/language_pairs_spec.rb +0 -40
  87. data/spec/requests/glossary/list_spec.rb +0 -54
  88. data/spec/requests/languages_spec.rb +0 -68
  89. data/spec/requests/rephrase_spec.rb +0 -172
  90. data/spec/requests/translate_spec.rb +0 -422
  91. data/spec/requests/usage_spec.rb +0 -43
  92. data/spec/resources/glossary_spec.rb +0 -38
  93. data/spec/resources/language_pair_spec.rb +0 -23
  94. data/spec/resources/language_spec.rb +0 -45
  95. data/spec/resources/text_spec.rb +0 -23
  96. data/spec/resources/usage_spec.rb +0 -35
  97. data/spec/spec_helper.rb +0 -92
@@ -1,460 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
- require 'tempfile'
8
-
9
- describe DeepL do
10
- subject(:deepl) { described_class.dup }
11
-
12
- around do |tests|
13
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
14
- tests.call
15
- ENV.replace(tmp_env)
16
- end
17
-
18
- describe '#configure' do
19
- context 'when providing no block' do
20
- let(:configuration) { DeepL::Configuration.new }
21
-
22
- before do
23
- deepl.configure
24
- end
25
-
26
- it 'uses default configuration' do
27
- expect(deepl.configuration).to eq(configuration)
28
- end
29
- end
30
-
31
- context 'when providing a valid configuration' do
32
- let(:configuration) do
33
- DeepL::Configuration.new({ auth_key: 'VALID', host: 'http://www.example.org',
34
- version: 'v1' })
35
- end
36
-
37
- before do
38
- deepl.configure do |config|
39
- config.auth_key = configuration.auth_key
40
- config.host = configuration.host
41
- config.version = configuration.version
42
- end
43
- end
44
-
45
- it 'uses the provided configuration' do
46
- expect(deepl.configuration).to eq(configuration)
47
- end
48
- end
49
-
50
- context 'when providing an invalid configuration' do
51
- it 'raises an error' do
52
- expect { deepl.configure { |c| c.auth_key = '' } }
53
- .to raise_error(DeepL::Exceptions::Error)
54
- end
55
- end
56
- end
57
-
58
- describe '#translate' do
59
- let(:input) { 'Sample' }
60
- let(:source_lang) { 'EN' }
61
- let(:target_lang) { 'ES' }
62
- let(:options) { { param: 'fake' } }
63
-
64
- around do |example|
65
- deepl.configure
66
- VCR.use_cassette('deepl_translate') { example.call }
67
- end
68
-
69
- context 'when translating a text' do
70
- it 'creates and call a request object' do
71
- expect(DeepL::Requests::Translate).to receive(:new)
72
- .with(deepl.api, input, source_lang, target_lang, options).and_call_original
73
-
74
- text = deepl.translate(input, source_lang, target_lang, options)
75
- expect(text).to be_a(DeepL::Resources::Text)
76
- end
77
- end
78
-
79
- context 'when translating a text using a glossary' do
80
- before do
81
- @glossary = deepl.glossaries.create('fixture', 'EN', 'ES', [%w[car auto]])
82
- end
83
-
84
- let(:input) { 'I wish we had a car.' }
85
- # rubocop:disable RSpec/InstanceVariable
86
- let(:options) { { glossary_id: @glossary.id } }
87
-
88
- after do
89
- deepl.glossaries.destroy(@glossary.id)
90
- end
91
- # rubocop:enable RSpec/InstanceVariable
92
-
93
- it 'creates and call a request object' do
94
- expect(DeepL::Requests::Translate).to receive(:new)
95
- .with(deepl.api, input, source_lang, target_lang, options).and_call_original
96
- text = deepl.translate(input, source_lang, target_lang, options)
97
- expect(text).to be_a(DeepL::Resources::Text)
98
- expect(text.text).to eq('Ojalá tuviéramos auto.')
99
- end
100
- end
101
- end
102
-
103
- describe '#usage' do
104
- let(:options) { {} }
105
-
106
- around do |example|
107
- deepl.configure
108
- VCR.use_cassette('deepl_usage') { example.call }
109
- end
110
-
111
- context 'when checking usage' do
112
- it 'creates and call a request object' do
113
- expect(DeepL::Requests::Usage).to receive(:new)
114
- .with(deepl.api, options).and_call_original
115
-
116
- usage = deepl.usage(options)
117
- expect(usage).to be_a(DeepL::Resources::Usage)
118
- end
119
- end
120
- end
121
-
122
- # rubocop:disable RSpec/InstanceVariable
123
- describe '#document' do
124
- describe '#document.upload' do
125
- before do
126
- @tmpfile = Tempfile.new('foo')
127
- @tmpfile.write("Geology for Beginners Report
128
- A test report for the DeepL API
129
- It is with great pleasure, that I, Urna Semper, write this fake document on geology.
130
- Geology is an excellent field that deals with how to extract oil from the earth.")
131
- @tmpfile.close
132
- end
133
-
134
- after do
135
- @tmpfile.unlink
136
- end
137
-
138
- let(:input_file) { @tmpfile.path }
139
- let(:source_lang) { 'EN' }
140
- let(:target_lang) { 'ES' }
141
- let(:output_file) { 'test_translated_doc.txt' }
142
- let(:options) { { param: 'fake' } }
143
- let(:additional_headers) { { 'Fake-Header': 'fake_value' } }
144
-
145
- around do |example|
146
- deepl.configure
147
- VCR.use_cassette('deepl_document') { example.call }
148
- end
149
-
150
- context 'when uploading a document' do
151
- it 'creates an upload object' do
152
- expect(DeepL::Requests::Document::Upload).to receive(:new)
153
- .with(deepl.api, input_file, source_lang, target_lang,
154
- "#{File.basename(@tmpfile.path)}.txt", options,
155
- additional_headers).and_call_original
156
- doc_handle = deepl.document.upload(input_file, source_lang, target_lang,
157
- "#{File.basename(@tmpfile.path)}.txt", options,
158
- additional_headers)
159
- expect(doc_handle).to be_a(DeepL::Resources::DocumentHandle)
160
- end
161
- end
162
- end
163
- # rubocop:enable RSpec/InstanceVariable
164
-
165
- describe '#document.get_status' do
166
- let(:document_handle) do
167
- DeepL::Resources::DocumentHandle.new('9B7CB9418DCDEBF2C4C519F65A32B99F',
168
- 'EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815', # rubocop:disable Layout/LineLength
169
- nil,
170
- nil)
171
- end
172
- let(:options) { { param: 'fake' } }
173
- let(:additional_headers) { { 'Fake-Header': 'fake_value' } }
174
-
175
- around do |example|
176
- deepl.configure
177
- VCR.use_cassette('deepl_document') { example.call }
178
- end
179
-
180
- context 'when querying the status of a document' do
181
- it 'creates a GetStatus object' do
182
- expect(DeepL::Requests::Document::GetStatus).to receive(:new)
183
- .with(
184
- deepl.api,
185
- document_handle.document_id,
186
- document_handle.document_key,
187
- options,
188
- additional_headers
189
- ).and_call_original
190
- status = deepl.document.get_status(document_handle, options, additional_headers)
191
- expect(status).to be_a(DeepL::Resources::DocumentTranslationStatus)
192
- end
193
- end
194
- end
195
-
196
- # rubocop:disable RSpec/InstanceVariable
197
- describe '#document.download' do
198
- before do
199
- @tmpfile = Tempfile.new('bar')
200
- end
201
-
202
- after do
203
- @tmpfile.close
204
- @tmpfile.unlink
205
- end
206
-
207
- let(:document_handle) do
208
- DeepL::Resources::DocumentHandle.new('9B7CB9418DCDEBF2C4C519F65A32B99F',
209
- 'EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815', # rubocop:disable Layout/LineLength
210
- nil,
211
- nil)
212
- end
213
- let(:output_file_path) { @tmpfile.path }
214
- let(:options) { { param: 'fake' } }
215
-
216
- around do |example|
217
- deepl.configure
218
- VCR.use_cassette('deepl_document_download', preserve_exact_body_bytes: true) do
219
- example.call
220
- end
221
- end
222
-
223
- context 'when downloading a document' do
224
- it 'creates an downloading object and writes to the output file' do # rubocop:disable RSpec/ExampleLength
225
- expect(DeepL::Requests::Document::Download).to receive(:new)
226
- .with(
227
- deepl.api,
228
- document_handle.document_id,
229
- document_handle.document_key,
230
- output_file_path
231
- ).and_call_original
232
- deepl.document.download(document_handle, output_file_path)
233
- file_contents = File.read(output_file_path)
234
- expect(file_contents).to be_a(String)
235
- expect(file_contents.length).to be > 200
236
- end
237
- end
238
- end
239
- end
240
- # rubocop:enable RSpec/InstanceVariable
241
-
242
- describe '#languages' do
243
- let(:options) { { type: :target } }
244
-
245
- around do |example|
246
- deepl.configure
247
- VCR.use_cassette('deepl_languages') { example.call }
248
- end
249
-
250
- context 'when checking languages' do
251
- it 'creates and call a request object' do
252
- expect(DeepL::Requests::Languages).to receive(:new)
253
- .with(deepl.api, options).and_call_original
254
-
255
- languages = deepl.languages(options)
256
- expect(languages).to be_an(Array)
257
- expect(languages).to(be_all { |l| l.is_a?(DeepL::Resources::Language) })
258
- end
259
- end
260
- end
261
-
262
- describe '#glossaries' do
263
- describe '#glossaries.create' do
264
- let(:name) { 'Mi Glosario' }
265
- let(:source_lang) { 'EN' }
266
- let(:target_lang) { 'ES' }
267
- let(:entries) do
268
- [
269
- %w[Hello Hola],
270
- %w[World Mundo]
271
- ]
272
- end
273
- let(:options) { { param: 'fake', entries_format: 'tsv' } }
274
-
275
- around do |example|
276
- deepl.configure
277
- VCR.use_cassette('deepl_glossaries') { example.call }
278
- end
279
-
280
- context 'when creating a glossary' do
281
- it 'creates and call a request object' do
282
- expect(DeepL::Requests::Glossary::Create).to receive(:new)
283
- .with(deepl.api, name, source_lang, target_lang, entries, options).and_call_original
284
-
285
- glossary = deepl.glossaries.create(name, source_lang, target_lang, entries, options)
286
- expect(glossary).to be_a(DeepL::Resources::Glossary)
287
- end
288
- end
289
- end
290
-
291
- describe '#glossaries.find' do
292
- let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
293
- let(:options) { {} }
294
-
295
- around do |example|
296
- deepl.configure
297
- VCR.use_cassette('deepl_glossaries') { example.call }
298
- end
299
-
300
- context 'when fetching a glossary' do
301
- it 'creates and call a request object' do
302
- expect(DeepL::Requests::Glossary::Find).to receive(:new)
303
- .with(deepl.api, id, options).and_call_original
304
-
305
- glossary = deepl.glossaries.find(id, options)
306
- expect(glossary).to be_a(DeepL::Resources::Glossary)
307
- end
308
- end
309
-
310
- context 'when fetching a non existing glossary' do
311
- let(:id) { '00000000-0000-0000-0000-000000000000' }
312
-
313
- it 'raises an exception when the glossary does not exist' do
314
- expect(DeepL::Requests::Glossary::Find).to receive(:new)
315
- .with(deepl.api, id, options).and_call_original
316
- expect { deepl.glossaries.find(id, options) }
317
- .to raise_error(DeepL::Exceptions::NotFound)
318
- end
319
- end
320
- end
321
-
322
- describe '#glossaries.list' do
323
- let(:options) { {} }
324
-
325
- around do |example|
326
- deepl.configure
327
- VCR.use_cassette('deepl_glossaries') { example.call }
328
- end
329
-
330
- context 'when fetching glossaries' do
331
- it 'creates and call a request object' do
332
- expect(DeepL::Requests::Glossary::List).to receive(:new)
333
- .with(deepl.api, options).and_call_original
334
-
335
- glossaries = deepl.glossaries.list(options)
336
- expect(glossaries).to all(be_a(DeepL::Resources::Glossary))
337
- end
338
- end
339
- end
340
-
341
- describe '#glossaries.destroy' do
342
- let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
343
- let(:options) { {} }
344
-
345
- around do |example|
346
- deepl.configure
347
- VCR.use_cassette('deepl_glossaries') { example.call }
348
- end
349
-
350
- context 'when destroy a glossary' do
351
- let(:new_glossary) do
352
- deepl.glossaries.create('fixture', 'EN', 'ES', [%w[Hello Hola]])
353
- end
354
-
355
- it 'creates and call a request object' do
356
- expect(DeepL::Requests::Glossary::Destroy).to receive(:new)
357
- .with(deepl.api, new_glossary.id, options).and_call_original
358
-
359
- glossary_id = deepl.glossaries.destroy(new_glossary.id, options)
360
- expect(glossary_id).to eq(new_glossary.id)
361
- end
362
- end
363
-
364
- context 'when destroying a non existing glossary' do
365
- let(:id) { '00000000-0000-0000-0000-000000000000' }
366
-
367
- it 'raises an exception when the glossary does not exist' do
368
- expect(DeepL::Requests::Glossary::Destroy).to receive(:new)
369
- .with(deepl.api, id, options).and_call_original
370
- expect { deepl.glossaries.destroy(id, options) }
371
- .to raise_error(DeepL::Exceptions::NotFound)
372
- end
373
- end
374
- end
375
-
376
- describe '#glossaries.entries' do
377
- let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
378
- let(:options) { {} }
379
-
380
- around do |example|
381
- deepl.configure
382
- VCR.use_cassette('deepl_glossaries') { example.call }
383
- end
384
-
385
- context 'when listing glossary entries' do
386
- it 'creates and call a request object' do
387
- expect(DeepL::Requests::Glossary::Entries).to receive(:new)
388
- .with(deepl.api, id, options).and_call_original
389
-
390
- entries = deepl.glossaries.entries(id, options)
391
- expect(entries).to all(be_a(Array))
392
- entries.each do |entry|
393
- expect(entry.size).to eq(2)
394
- expect(entry.first).to be_a(String)
395
- expect(entry.last).to be_a(String)
396
- end
397
- end
398
- end
399
-
400
- context 'when listing entries of a non existing glossary' do
401
- let(:id) { '00000000-0000-0000-0000-000000000000' }
402
-
403
- it 'raises an exception when the glossary does not exist' do
404
- expect(DeepL::Requests::Glossary::Entries).to receive(:new)
405
- .with(deepl.api, id, options).and_call_original
406
- expect { deepl.glossaries.entries(id, options) }
407
- .to raise_error(DeepL::Exceptions::NotFound)
408
- end
409
- end
410
- end
411
-
412
- describe '#glossaries.language_pairs' do
413
- let(:options) { {} }
414
-
415
- around do |example|
416
- deepl.configure
417
- VCR.use_cassette('deepl_glossaries') { example.call }
418
- end
419
-
420
- context 'when fetching language pairs supported by glossaries' do
421
- it 'creates and call a request object' do
422
- expect(DeepL::Requests::Glossary::LanguagePairs).to receive(:new)
423
- .with(deepl.api, options).and_call_original
424
-
425
- language_pairs = deepl.glossaries.language_pairs(options)
426
- expect(language_pairs).to all(be_a(DeepL::Resources::LanguagePair))
427
- end
428
- end
429
- end
430
- end
431
-
432
- describe '#rephrase' do
433
- let(:text) { 'Ih bin ei beispielsatz.' }
434
- let(:target_lang) { 'DE' }
435
- let(:options) { {} }
436
-
437
- around do |example|
438
- deepl.configure
439
- VCR.use_cassette('deepl_rephrase') { example.call }
440
- end
441
-
442
- context 'when rephrasing text' do
443
- it 'creates and call a request object' do
444
- expect(DeepL::Requests::Rephrase).to receive(:new)
445
- .with(deepl.api, text, nil, nil, nil, {}).and_call_original
446
-
447
- rephrased_text = deepl.rephrase(text)
448
- expect(rephrased_text).to be_a(DeepL::Resources::Text)
449
- end
450
-
451
- it 'creates and call a request object when passing options' do
452
- expect(DeepL::Requests::Rephrase).to receive(:new)
453
- .with(deepl.api, text, target_lang, nil, nil, options).and_call_original
454
-
455
- rephrased_text = deepl.rephrase(text, target_lang, nil, nil, options)
456
- expect(rephrased_text).to be_a(DeepL::Resources::Text)
457
- end
458
- end
459
- end
460
- end
@@ -1,158 +0,0 @@
1
- # Copyright 2025 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.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe 'DeepL::Constants' do
9
- describe DeepL::Constants::Tone do
10
- subject(:tone) { described_class }
11
-
12
- it 'includes all expected tone values' do # rubocop:disable RSpec/ExampleLength
13
- expect(tone.options).to contain_exactly(
14
- 'confident',
15
- 'default',
16
- 'diplomatic',
17
- 'enthusiastic',
18
- 'friendly',
19
- 'prefer_confident',
20
- 'prefer_diplomatic',
21
- 'prefer_enthusiastic',
22
- 'prefer_friendly'
23
- )
24
- end
25
-
26
- it 'validates correct tone values' do
27
- expect(tone.valid?('enthusiastic')).to be true
28
- expect(tone.valid?('friendly')).to be true
29
- expect(tone.valid?('confident')).to be true
30
- expect(tone.valid?('diplomatic')).to be true
31
- expect(tone.valid?('default')).to be true
32
- end
33
-
34
- it 'invalidates incorrect tone values' do
35
- expect(tone.valid?('angry')).to be false
36
- expect(tone.valid?('')).to be false
37
- expect(tone.valid?(nil)).to be false
38
- end
39
- end
40
-
41
- describe DeepL::Constants::WritingStyle do
42
- subject(:writing_style) { described_class }
43
-
44
- it 'includes all expected writing style values' do # rubocop:disable RSpec/ExampleLength
45
- expect(writing_style.options).to contain_exactly(
46
- 'default',
47
- 'simple',
48
- 'business',
49
- 'academic',
50
- 'casual',
51
- 'prefer_academic',
52
- 'prefer_business',
53
- 'prefer_casual',
54
- 'prefer_simple'
55
- )
56
- end
57
-
58
- it 'validates correct writing style values' do
59
- expect(writing_style.valid?('simple')).to be true
60
- expect(writing_style.valid?('business')).to be true
61
- expect(writing_style.valid?('academic')).to be true
62
- expect(writing_style.valid?('casual')).to be true
63
- expect(writing_style.valid?('default')).to be true
64
- end
65
-
66
- it 'invalidates incorrect writing style values' do
67
- expect(writing_style.valid?('wordy')).to be false
68
- expect(writing_style.valid?('')).to be false
69
- expect(writing_style.valid?(nil)).to be false
70
- end
71
- end
72
-
73
- describe DeepL::Constants::TagHandling do
74
- subject(:tag_handling) { described_class }
75
-
76
- it 'includes all expected tag handling values' do
77
- expect(tag_handling.options).to contain_exactly('xml', 'html')
78
- end
79
-
80
- it 'validates correct tag handling values' do
81
- expect(tag_handling.valid?('xml')).to be true
82
- expect(tag_handling.valid?('html')).to be true
83
- end
84
-
85
- it 'invalidates incorrect tag handling values' do
86
- expect(tag_handling.valid?('json')).to be false
87
- expect(tag_handling.valid?('')).to be false
88
- expect(tag_handling.valid?(nil)).to be false
89
- end
90
- end
91
-
92
- describe DeepL::Constants::SplitSentences do
93
- subject(:split_sentences) { described_class }
94
-
95
- it 'includes all expected split sentences values' do
96
- expect(split_sentences.options).to contain_exactly('0', '1', 'nonewlines')
97
- end
98
-
99
- it 'validates correct split sentences values' do
100
- expect(split_sentences.valid?('0')).to be true
101
- expect(split_sentences.valid?('1')).to be true
102
- expect(split_sentences.valid?('nonewlines')).to be true
103
- end
104
-
105
- it 'invalidates incorrect split sentences values' do
106
- expect(split_sentences.valid?('2')).to be false
107
- expect(split_sentences.valid?('')).to be false
108
- expect(split_sentences.valid?(nil)).to be false
109
- end
110
- end
111
-
112
- describe DeepL::Constants::ModelType do
113
- subject(:model_type) { described_class }
114
-
115
- it 'includes all expected model type values' do
116
- expect(model_type.options).to contain_exactly(
117
- 'quality_optimized',
118
- 'prefer_quality_optimized',
119
- 'latency_optimized'
120
- )
121
- end
122
-
123
- it 'validates correct model type values' do
124
- expect(model_type.valid?('quality_optimized')).to be true
125
- expect(model_type.valid?('prefer_quality_optimized')).to be true
126
- expect(model_type.valid?('latency_optimized')).to be true
127
- end
128
-
129
- it 'invalidates incorrect model type values' do
130
- expect(model_type.valid?('speed_optimized')).to be false
131
- expect(model_type.valid?('')).to be false
132
- expect(model_type.valid?(nil)).to be false
133
- end
134
- end
135
-
136
- describe DeepL::Constants::Formality do
137
- subject(:formality) { described_class }
138
-
139
- it 'includes all expected formality values' do
140
- expect(formality.options).to contain_exactly('default', 'more', 'less', 'prefer_more',
141
- 'prefer_less')
142
- end
143
-
144
- it 'validates correct formality values' do
145
- expect(formality.valid?('default')).to be true
146
- expect(formality.valid?('more')).to be true
147
- expect(formality.valid?('less')).to be true
148
- expect(formality.valid?('prefer_more')).to be true
149
- expect(formality.valid?('prefer_less')).to be true
150
- end
151
-
152
- it 'invalidates incorrect formality values' do
153
- expect(formality.valid?('neutral')).to be false
154
- expect(formality.valid?('')).to be false
155
- expect(formality.valid?(nil)).to be false
156
- end
157
- end
158
- end