spec/faraday/connection_spec.rb in faraday-2.0.0.alpha.pre.2 vs spec/faraday/connection_spec.rb in faraday-2.0.0.alpha.pre.3

- old
+ new

@@ -637,9 +637,30 @@ context 'assigning a hash' do before { Faraday.default_connection_options = { request: { timeout: 10 } } } it_behaves_like 'default connection options' end + + context 'preserving a user_agent assigned via default_conncetion_options' do + around do |example| + old = Faraday.default_connection_options + Faraday.default_connection_options = { headers: { user_agent: 'My Agent 1.2' } } + example.run + Faraday.default_connection_options = old + end + + context 'when url is a Hash' do + let(:conn) { Faraday.new(url: 'http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) } + + it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') } + end + + context 'when url is a String' do + let(:conn) { Faraday.new('http://example.co', headers: { 'CustomHeader' => 'CustomValue' }) } + + it { expect(conn.headers).to eq('CustomHeader' => 'CustomValue', 'User-Agent' => 'My Agent 1.2') } + end + end end describe 'request params' do context 'with simple url' do let(:url) { 'http://example.com' }