@@ -26,94 +26,21 @@ class BiDi
2626 describe Headers do
2727 let ( :headers ) { described_class . new }
2828
29- describe '#initialize' do
30- it 'initializes an empty headers hash' do
31- expect ( headers . all ) . to eq ( { } )
32- end
33- end
34-
35- describe '#all' do
36- it 'returns the underlying headers hash' do
37- headers [ 'Authorization' ] = 'Bearer abc123'
38- expect ( headers . all ) . to eq ( { 'Authorization' => 'Bearer abc123' } )
39- end
40- end
41-
42- describe '#add_header' do
43- it 'adds a header to the internal store' do
44- headers [ 'Content-Type' ] = 'application/json'
45- expect ( headers [ 'Content-Type' ] ) . to eq ( 'application/json' )
46- end
47-
48- it 'updates an existing header if the name already exists' do
49- headers [ 'Content-Type' ] = 'text/html'
50- headers [ 'Content-Type' ] = 'application/json'
51- expect ( headers [ 'Content-Type' ] ) . to eq ( 'application/json' )
52- end
53- end
54-
55- describe '#remove_header' do
56- it 'removes a header by name' do
57- headers [ 'X-Custom-Header' ] = 'foo'
58- headers . delete ( 'X-Custom-Header' )
59- expect ( headers [ 'X-Custom-Header' ] ) . to be_nil
60- end
61-
62- it 'does not raise an error if header does not exist' do
63- expect { headers . delete ( 'Non-Existent' ) } . not_to raise_error
64- end
65- end
66-
67- describe '#[]=' do
68- it 'adds or updates a header using bracket assignment' do
69- headers [ 'Cache-Control' ] = 'no-cache'
70- expect ( headers [ 'Cache-Control' ] ) . to eq ( 'no-cache' )
71-
72- headers [ 'Cache-Control' ] = 'private'
73- expect ( headers [ 'Cache-Control' ] ) . to eq ( 'private' )
74- end
75- end
76-
77- describe '#[]' do
78- it 'retrieves the value of a header by name' do
79- headers [ 'Host' ] = 'example.com'
80- expect ( headers [ 'Host' ] ) . to eq ( 'example.com' )
81- end
82-
83- it 'returns nil for unknown headers' do
84- expect ( headers [ 'Does-Not-Exist' ] ) . to be_nil
85- end
86- end
87-
88- describe '#delete' do
89- it 'removes a header via bracket-based delete' do
90- headers [ 'Accept' ] = 'text/html'
91- headers . delete ( 'Accept' )
92- expect ( headers [ 'Accept' ] ) . to be_nil
93- end
94- end
95-
96- describe '#serialize' do
97- it 'returns an array of header hashes in the correct format' do
98- headers [ 'Accept' ] = 'application/json'
99- headers [ 'User-Agent' ] = 'MyAgent/1.0'
100-
101- serialized = headers . serialize
102- expect ( serialized ) . to be_an ( Array )
103- expect ( serialized . size ) . to eq ( 2 )
29+ it 'returns an array of serialized array of header hashes' do
30+ headers [ 'Accept' ] = 'application/json'
31+ headers [ 'User-Agent' ] = 'MyAgent/1.0'
10432
105- accept_item = serialized . find { | h | h [ :name ] == 'Accept' }
106- expect ( accept_item ) . not_to be_nil
107- expect ( accept_item [ :value ] ) . to eq ( { type : 'string' , value : 'application/json' } )
33+ serialized = headers . serialize
34+ expect ( serialized ) . to be_an ( Array )
35+ expect ( serialized . size ) . to eq ( 2 )
10836
109- ua_item = serialized . find { |h | h [ :name ] == 'User-Agent' }
110- expect ( ua_item ) . not_to be_nil
111- expect ( ua_item [ :value ] ) . to eq ( { type : 'string' , value : 'MyAgent/1.0' } )
112- end
37+ accept_item = serialized . find { |h | h [ :name ] == 'Accept' }
38+ expect ( accept_item ) . not_to be_nil
39+ expect ( accept_item [ :value ] ) . to eq ( { type : 'string' , value : 'application/json' } )
11340
114- it 'returns an empty array if no headers are set' do
115- expect ( headers . serialize ) . to eq ( [ ] )
116- end
41+ ua_item = serialized . find { | h | h [ :name ] == 'User-Agent' }
42+ expect ( ua_item ) . not_to be_nil
43+ expect ( ua_item [ :value ] ) . to eq ( { type : 'string' , value : 'MyAgent/1.0' } )
11744 end
11845 end
11946 end
0 commit comments