deepl-rb 2.5.0 → 2.5.2

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.
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe DeepL::Requests::Translate do
6
- let(:tags_str) { 'p, strong, span' }
6
+ let(:tags_str) { 'p,strong,span' }
7
7
  let(:tags_array) { %w[p strong span] }
8
8
 
9
9
  let(:api) { build_deepl_api }
@@ -11,6 +11,7 @@ describe DeepL::Requests::Translate do
11
11
  let(:source_lang) { 'EN' }
12
12
  let(:target_lang) { 'ES' }
13
13
  let(:options) { {} }
14
+
14
15
  subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
15
16
 
16
17
  describe '#initialize' do
@@ -20,6 +21,33 @@ describe DeepL::Requests::Translate do
20
21
  end
21
22
  end
22
23
 
24
+ context 'when using `splitting_tags` options' do
25
+ it 'should work with a nil values' do
26
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: nil)
27
+ expect(request.options[:splitting_tags]).to eq(nil)
28
+ end
29
+
30
+ it 'should work with a blank list' do
31
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: '')
32
+ expect(request.options[:splitting_tags]).to eq('')
33
+ end
34
+
35
+ it 'should work with a comma-separated list' do
36
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
37
+ expect(request.options[:splitting_tags]).to eq(tags_str)
38
+ end
39
+
40
+ it 'should convert arrays to strings' do
41
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_array)
42
+ expect(request.options[:splitting_tags]).to eq(tags_str)
43
+ end
44
+
45
+ it 'should leave strings as they are' do
46
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
47
+ expect(request.options[:splitting_tags]).to eq(tags_str)
48
+ end
49
+ end
50
+
23
51
  context 'when using `non_splitting_tags` options' do
24
52
  it 'should work with a nil values' do
25
53
  request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: nil)
@@ -215,7 +243,7 @@ describe DeepL::Requests::Translate do
215
243
 
216
244
  context 'When performing a valid request and passing a variable' do
217
245
  let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
218
- let(:options) { { tag_handling: 'xml', ignore_tags: 'code,span' } }
246
+ let(:options) { { tag_handling: 'xml', ignore_tags: %w[code span] } }
219
247
 
220
248
  it 'should return a text object' do
221
249
  text = subject.request
@@ -226,6 +254,50 @@ describe DeepL::Requests::Translate do
226
254
  end
227
255
  end
228
256
 
257
+ context 'When performing a valid request with an HTML document' do
258
+ let(:text) do
259
+ <<~XML
260
+ <document>
261
+ <meta>
262
+ <title>A document's title</title>
263
+ </meta>
264
+ <content>
265
+ <par>This is the first sentence. Followed by a second one.</par>
266
+ <par>This is the third sentence.</par>
267
+ </content>
268
+ </document>
269
+ XML
270
+ end
271
+ let(:options) do
272
+ {
273
+ tag_handling: 'xml',
274
+ split_sentences: 'nonewlines',
275
+ outline_detection: false,
276
+ splitting_tags: %w[title par]
277
+ }
278
+ end
279
+
280
+ it 'should return a text object' do
281
+ text = subject.request
282
+
283
+ expect(text).to be_a(DeepL::Resources::Text)
284
+ expect(text.text).to eq(
285
+ <<~XML
286
+ <document>
287
+ <meta>
288
+ <title>El título de un documento</title>
289
+ </meta>
290
+ <content>
291
+ <par>Es la primera frase. Seguido de una segunda.</par>
292
+ <par>Esta es la tercera frase.</par>
293
+ </content>
294
+ </document>
295
+ XML
296
+ )
297
+ expect(text.detected_source_language).to eq('EN')
298
+ end
299
+ end
300
+
229
301
  context 'When performing a bad request' do
230
302
  context 'When using an invalid token' do
231
303
  let(:api) do
@@ -257,5 +329,14 @@ describe DeepL::Requests::Translate do
257
329
  end
258
330
  end
259
331
  end
332
+
333
+ context 'When performing a request with too many texts' do
334
+ let(:text) { Array.new(10_000) { |i| "This is the sentence number #{i}" } }
335
+
336
+ it 'should raise a request entity too large error' do
337
+ expect { subject.request }.to raise_error(DeepL::Exceptions::RequestEntityTooLarge,
338
+ /request size has reached the supported limit/)
339
+ end
340
+ end
260
341
  end
261
342
  end
data/spec/spec_helper.rb CHANGED
@@ -18,7 +18,7 @@ require 'vcr'
18
18
  VCR.configure do |config|
19
19
  config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
20
20
  config.hook_into :webmock
21
- config.filter_sensitive_data('VALID_TOKEN') { ENV['DEEPL_AUTH_KEY'] }
21
+ config.filter_sensitive_data('VALID_TOKEN') { ENV.fetch('DEEPL_AUTH_KEY', nil) }
22
22
  config.default_cassette_options = {
23
23
  # record: :new_episodes,
24
24
  match_requests_on: %i[method uri body headers]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepl-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Herzog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-06 00:00:00.000000000 Z
11
+ date: 2022-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier
@@ -65,6 +65,7 @@ files:
65
65
  - lib/deepl/exceptions/not_found.rb
66
66
  - lib/deepl/exceptions/not_supported.rb
67
67
  - lib/deepl/exceptions/quota_exceeded.rb
68
+ - lib/deepl/exceptions/request_entity_too_large.rb
68
69
  - lib/deepl/exceptions/request_error.rb
69
70
  - lib/deepl/glossary_api.rb
70
71
  - lib/deepl/requests/base.rb
@@ -83,6 +84,7 @@ files:
83
84
  - lib/deepl/resources/language_pair.rb
84
85
  - lib/deepl/resources/text.rb
85
86
  - lib/deepl/resources/usage.rb
87
+ - lib/deepl/utils/exception_builder.rb
86
88
  - spec/api/api_spec.rb
87
89
  - spec/api/configuration_spec.rb
88
90
  - spec/api/deepl_spec.rb