File: merged.rb

package info (click to toggle)
ruby-protocol-http 0.55.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 840 kB
  • sloc: ruby: 6,904; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
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
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2025, by Samuel Williams.

require "protocol/http/headers"

describe Protocol::HTTP::Headers::Merged do	
	let(:fields) do
		[
			["Content-Type", "text/html"],
			["Set-Cookie", "hello=world"],
			["Accept", "*/*"],
			["content-length", 10],
		]
	end
	
	let(:merged) {subject.new(fields)}
	let(:headers) {Protocol::HTTP::Headers.new(merged)}
	
	with "#each" do
		it "should yield keys as lower case" do
			merged.each do |key, value|
				expect(key).to be == key.downcase
			end
		end
		
		it "should yield values as strings" do
			merged.each do |key, value|
				expect(value).to be_a(String)
			end
		end
	end
	
	with "#<<" do
		it "can append fields" do
			merged << [["Accept", "image/jpeg"]]
			
			expect(headers["accept"]).to be == ["*/*", "image/jpeg"]
		end
	end
end