Skip to content

Commit ee33e3e

Browse files
committed
FIX: default with_session client options
The default `HTTPClientOptions.new()` parameter in `with_session` method raises an error. According to the [README](https://github.com/DeepLcom/deepl-rb/blob/1f63db3b704ec532c0b970a52fb8ec90c6986e84/README.md?plain=1#L344-L350) it should be possible to call `with_session` without passing any arguments.
1 parent 1f63db3 commit ee33e3e

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

lib/http_client_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class HTTPClientOptions
88
attr_reader :proxy, :send_platform_info, :enable_ssl_verification, :cert_path, :open_timeout,
99
:read_timeout, :write_timeout, :ssl_timeout
1010

11-
def initialize(proxy, cert_path, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
11+
def initialize(proxy = {}, cert_path = nil, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
1212
read_timeout: nil, write_timeout: nil, ssl_timeout: nil)
1313
@proxy = proxy
1414
@enable_ssl_verification = enable_ssl_verification

spec/http_client_options_spec.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2024 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::HTTPClientOptions do
9+
describe '#initialize' do
10+
context 'when initialized without arguments' do
11+
it 'sets default values' do
12+
options = DeepL::HTTPClientOptions.new
13+
expect(options.proxy).to eq({})
14+
expect(options.cert_path).to be_nil
15+
expect(options.enable_ssl_verification).to be true
16+
expect(options.open_timeout).to be_nil
17+
expect(options.read_timeout).to be_nil
18+
expect(options.write_timeout).to be_nil
19+
expect(options.ssl_timeout).to be_nil
20+
end
21+
end
22+
23+
context 'when initialized with all parameters' do
24+
it 'sets all attributes correctly' do
25+
proxy = { 'proxy_addr' => 'proxy.example.com', 'proxy_port' => 8080 }
26+
cert_path = '/path/to/cert.pem'
27+
options = DeepL::HTTPClientOptions.new(
28+
proxy,
29+
cert_path,
30+
enable_ssl_verification: false,
31+
open_timeout: 5,
32+
read_timeout: 10,
33+
write_timeout: 15,
34+
ssl_timeout: 20
35+
)
36+
expect(options.proxy).to eq(proxy)
37+
expect(options.proxy['proxy_addr']).to eq('proxy.example.com')
38+
expect(options.proxy['proxy_port']).to eq(8080)
39+
40+
expect(options.cert_path).to eq(cert_path)
41+
expect(options.enable_ssl_verification).to be false
42+
expect(options.open_timeout).to eq(5)
43+
expect(options.read_timeout).to eq(10)
44+
expect(options.write_timeout).to eq(15)
45+
expect(options.ssl_timeout).to eq(20)
46+
end
47+
end
48+
49+
context 'when initialized with invalid keyword arguments' do
50+
it 'raises an ArgumentError' do
51+
expect {
52+
DeepL::HTTPClientOptions.new({}, nil, invalid_option: true)
53+
}.to raise_error(ArgumentError)
54+
end
55+
end
56+
57+
context 'attribute readers' do
58+
it 'does not allow attributes to be modified after initialization' do
59+
options = DeepL::HTTPClientOptions.new
60+
expect {
61+
options.proxy = { 'proxy_addr' => 'new.proxy.com' }
62+
}.to raise_error(NoMethodError)
63+
end
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)