Skip to content

Commit

Permalink
FIX: default with_session client options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rreckonerr committed Oct 2, 2024
1 parent 1f63db3 commit ee33e3e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/http_client_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HTTPClientOptions
attr_reader :proxy, :send_platform_info, :enable_ssl_verification, :cert_path, :open_timeout,
:read_timeout, :write_timeout, :ssl_timeout

def initialize(proxy, cert_path, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
def initialize(proxy = {}, cert_path = nil, enable_ssl_verification: true, open_timeout: nil, # rubocop:disable Metrics/ParameterLists
read_timeout: nil, write_timeout: nil, ssl_timeout: nil)
@proxy = proxy
@enable_ssl_verification = enable_ssl_verification
Expand Down
66 changes: 66 additions & 0 deletions spec/http_client_options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2024 DeepL SE (https://www.deepl.com)
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
# frozen_string_literal: true

require 'spec_helper'

describe DeepL::HTTPClientOptions do
describe '#initialize' do
context 'when initialized without arguments' do
it 'sets default values' do
options = DeepL::HTTPClientOptions.new
expect(options.proxy).to eq({})
expect(options.cert_path).to be_nil
expect(options.enable_ssl_verification).to be true
expect(options.open_timeout).to be_nil
expect(options.read_timeout).to be_nil
expect(options.write_timeout).to be_nil
expect(options.ssl_timeout).to be_nil
end
end

context 'when initialized with all parameters' do
it 'sets all attributes correctly' do
proxy = { 'proxy_addr' => 'proxy.example.com', 'proxy_port' => 8080 }
cert_path = '/path/to/cert.pem'
options = DeepL::HTTPClientOptions.new(
proxy,
cert_path,
enable_ssl_verification: false,
open_timeout: 5,
read_timeout: 10,
write_timeout: 15,
ssl_timeout: 20
)
expect(options.proxy).to eq(proxy)
expect(options.proxy['proxy_addr']).to eq('proxy.example.com')
expect(options.proxy['proxy_port']).to eq(8080)

expect(options.cert_path).to eq(cert_path)
expect(options.enable_ssl_verification).to be false
expect(options.open_timeout).to eq(5)
expect(options.read_timeout).to eq(10)
expect(options.write_timeout).to eq(15)
expect(options.ssl_timeout).to eq(20)
end
end

context 'when initialized with invalid keyword arguments' do
it 'raises an ArgumentError' do
expect {
DeepL::HTTPClientOptions.new({}, nil, invalid_option: true)
}.to raise_error(ArgumentError)
end
end

context 'attribute readers' do
it 'does not allow attributes to be modified after initialization' do
options = DeepL::HTTPClientOptions.new
expect {
options.proxy = { 'proxy_addr' => 'new.proxy.com' }
}.to raise_error(NoMethodError)
end
end
end
end

0 comments on commit ee33e3e

Please sign in to comment.