Skip to content

Commit ce8b579

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/rreckonerr/deepl-rb/blob/cf44150ebad923fffc0909e3aad9fe183bb05915/README.md?plain=1#L344-L350) it should be possible to call `with_session` without passing any arguments.
1 parent 1f63db3 commit ce8b579

File tree

2 files changed

+64
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)