-
Notifications
You must be signed in to change notification settings - Fork 968
/
utils_spec.rb
56 lines (45 loc) · 1.55 KB
/
utils_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
RSpec.describe Faraday::Utils do
describe 'headers parsing' do
let(:multi_response_headers) do
"HTTP/1.x 500 OK\r\nContent-Type: text/html; charset=UTF-8\r\n" \
"HTTP/1.x 200 OK\r\nContent-Type: application/json; charset=UTF-8\r\n\r\n"
end
it 'parse headers for aggregated responses' do
headers = Faraday::Utils::Headers.new
headers.parse(multi_response_headers)
result = headers.to_hash
expect(result['Content-Type']).to eq('application/json; charset=UTF-8')
end
end
describe 'URI parsing' do
let(:url) { 'http://example.com/abc' }
it 'escapes safe buffer' do
str = FakeSafeBuffer.new('$32,000.00')
expect(Faraday::Utils.escape(str)).to eq('%2432%2C000.00')
end
it 'parses with default parser' do
with_default_uri_parser(nil) do
uri = normalize(url)
expect(uri.host).to eq('example.com')
end
end
it 'parses with URI' do
with_default_uri_parser(::URI) do
uri = normalize(url)
expect(uri.host).to eq('example.com')
end
end
it 'parses with block' do
with_default_uri_parser(->(u) { "booya#{'!' * u.size}" }) do
expect(normalize(url)).to eq('booya!!!!!!!!!!!!!!!!!!!!!!')
end
end
it 'replaces headers hash' do
headers = Faraday::Utils::Headers.new('authorization' => 't0ps3cr3t!')
expect(headers).to have_key('authorization')
headers.replace('content-type' => 'text/plain')
expect(headers).not_to have_key('authorization')
end
end
end