File: vary.rb

package info (click to toggle)
ruby-protocol-http 0.59.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 864 kB
  • sloc: ruby: 7,612; makefile: 4
file content (70 lines) | stat: -rw-r--r-- 1,978 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

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

require "protocol/http/header/vary"

describe Protocol::HTTP::Header::Vary do
	let(:header) {subject.parse(description)}
	
	with "#<<" do
		it "can append normalised header names" do
			header << "Accept-Language"
			expect(header).to be(:include?, "accept-language")
		end
	end
	
	with "accept-language" do
		it "should be case insensitive" do
			expect(header).to be(:include?, "accept-language")
		end
		
		it "should not have unspecific keys" do
			expect(header).not.to be(:include?, "user-agent")
		end
	end
	
	with "Accept-Language" do
		it "should be case insensitive" do
			expect(header).to be(:include?, "accept-language")
		end
		
		it "uses normalised lower case keys" do
			expect(header).not.to be(:include?, "Accept-Language")
		end
	end
	
	with ".coerce" do
		it "normalizes array values to lowercase" do
			header = subject.coerce(["Accept-Language", "User-Agent"])
			expect(header).to be(:include?, "accept-language")
			expect(header).to be(:include?, "user-agent")
			expect(header).not.to be(:include?, "Accept-Language")
		end
		
		it "normalizes string values to lowercase" do
			header = subject.coerce("Accept-Language, User-Agent")
			expect(header).to be(:include?, "accept-language")
			expect(header).to be(:include?, "user-agent")
		end
	end
	
	with ".new" do
		it "preserves case when given array" do
			header = subject.new(["Accept-Language", "User-Agent"])
			expect(header).to be(:include?, "Accept-Language")
			expect(header).to be(:include?, "User-Agent")
		end
		
		it "can initialize with string for backward compatibility" do
			header = subject.new("Accept-Language, User-Agent")
			expect(header).to be(:include?, "accept-language")
			expect(header).to be(:include?, "user-agent")
		end
		
		it "raises ArgumentError for invalid value types" do
			expect{subject.new(123)}.to raise_exception(ArgumentError)
		end
	end
end