|
| 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