Skip to content

Commit 0d9d06c

Browse files
100% test coverage.
1 parent 8998f55 commit 0d9d06c

File tree

13 files changed

+120
-0
lines changed

13 files changed

+120
-0
lines changed

test/protocol/http/header/accept.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,30 @@
8383
)
8484
end
8585
end
86+
87+
with ".coerce" do
88+
it "coerces array to Accept" do
89+
result = subject.coerce(["text/html", "application/json"])
90+
expect(result).to be_a(subject)
91+
expect(result).to be == ["text/html", "application/json"]
92+
end
93+
94+
it "coerces string to Accept" do
95+
result = subject.coerce("text/html, application/json")
96+
expect(result).to be_a(subject)
97+
expect(result).to be(:include?, "text/html")
98+
end
99+
end
100+
101+
with "backward compatibility" do
102+
it "can initialize with string" do
103+
header = subject.new("text/plain, text/html")
104+
expect(header).to be(:include?, "text/plain")
105+
expect(header).to be(:include?, "text/html")
106+
end
107+
108+
it "raises ArgumentError for invalid value types" do
109+
expect{subject.new(123)}.to raise_exception(ArgumentError)
110+
end
111+
end
86112
end

test/protocol/http/header/authorization.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@
2020
end
2121
end
2222
end
23+
24+
with ".parse" do
25+
it "parses raw authorization value" do
26+
result = subject.parse("Bearer token123")
27+
expect(result).to be_a(subject)
28+
expect(result).to be == "Bearer token123"
29+
end
30+
end
31+
32+
with ".coerce" do
33+
it "coerces string to Authorization" do
34+
result = subject.coerce("Bearer xyz")
35+
expect(result).to be_a(subject)
36+
expect(result).to be == "Bearer xyz"
37+
end
38+
end
2339
end

test/protocol/http/header/cache_control.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,9 @@
104104
expect(header).not.to be(:include?, "PUBLIC")
105105
expect(header).not.to be(:include?, "NO-CACHE")
106106
end
107+
108+
it "raises ArgumentError for invalid value types" do
109+
expect{subject.new(123)}.to raise_exception(ArgumentError)
110+
end
107111
end
108112
end

test/protocol/http/header/connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,9 @@
7373
expect(header).not.to be(:include?, "CLOSE")
7474
expect(header).not.to be(:include?, "UPGRADE")
7575
end
76+
77+
it "raises ArgumentError for invalid value types" do
78+
expect{subject.new(123)}.to raise_exception(ArgumentError)
79+
end
7680
end
7781
end

test/protocol/http/header/date.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
end
4545
end
4646

47+
with ".coerce" do
48+
it "coerces string to Date" do
49+
result = subject.coerce("Wed, 21 Oct 2015 07:28:00 GMT")
50+
expect(result).to be_a(subject)
51+
expect(result.to_time.year).to be == 2015
52+
end
53+
end
54+
4755
describe Protocol::HTTP::Headers do
4856
let(:headers) {subject[[
4957
["Date", "Wed, 21 Oct 2015 07:28:00 GMT"],

test/protocol/http/header/etag.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@
3131
expect(header).to be(:weak?)
3232
end
3333
end
34+
35+
with ".coerce" do
36+
it "coerces string to ETag" do
37+
result = subject.coerce('"xyz"')
38+
expect(result).to be_a(subject)
39+
expect(result).to be == '"xyz"'
40+
end
41+
end
3442
end

test/protocol/http/header/multiple.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,18 @@
2525
expect(subject).not.to be(:trailer?)
2626
end
2727
end
28+
29+
with ".coerce" do
30+
it "coerces array to Multiple" do
31+
result = subject.coerce(["value1", "value2"])
32+
expect(result).to be_a(subject)
33+
expect(result).to be == ["value1", "value2"]
34+
end
35+
36+
it "coerces string to Multiple" do
37+
result = subject.coerce("single-value")
38+
expect(result).to be_a(subject)
39+
expect(result).to be == ["single-value"]
40+
end
41+
end
2842
end

test/protocol/http/header/priority.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,9 @@
9696
expect(header).not.to be(:include?, "U=3")
9797
expect(header).not.to be(:include?, "I")
9898
end
99+
100+
it "raises ArgumentError for invalid value types" do
101+
expect{subject.new(123)}.to raise_exception(ArgumentError)
102+
end
99103
end
100104
end

test/protocol/http/header/te.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@
120120
expect(header).not.to be(:include?, "GZIP")
121121
expect(header).not.to be(:include?, "CHUNKED")
122122
end
123+
124+
it "raises ArgumentError for invalid value types" do
125+
expect{subject.new(123)}.to raise_exception(ArgumentError)
126+
end
123127
end
124128
end
125129

test/protocol/http/header/trailer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,16 @@
7373
expect(subject).not.to be(:trailer?)
7474
end
7575
end
76+
77+
with "backward compatibility" do
78+
it "can initialize with string for backward compatibility" do
79+
header = subject.new("etag, content-md5")
80+
expect(header).to be(:include?, "etag")
81+
expect(header).to be(:include?, "content-md5")
82+
end
83+
84+
it "raises ArgumentError for invalid value types" do
85+
expect{subject.new(123)}.to raise_exception(ArgumentError)
86+
end
87+
end
7688
end

0 commit comments

Comments
 (0)