Skip to content

Commit dcbc0fe

Browse files
Cover header quality comparisons.
Assisted-By: devx/71d171da-b98c-42c2-922b-36328d89d0d6
1 parent 0f3e285 commit dcbc0fe

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎test/protocol/http/header/accept.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
expect(media_range.quality_factor).to be == 1.0
1212
end
1313

14+
it "compares by quality factor" do
15+
high = subject.new("text", "html", {"q" => "0.9"})
16+
low = subject.new("text", "plain", {"q" => "0.5"})
17+
expect(high <=> low).to be == -1
18+
end
19+
1420
with "#to_s" do
1521
it "can convert to string" do
1622
media_range = subject.new("text", "plain", {"q" => "0.5"})

‎test/protocol/http/header/accept_charset.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
charset = subject.new("utf-8", nil)
1111
expect(charset.quality_factor).to be == 1.0
1212
end
13+
14+
it "compares by quality factor" do
15+
high = subject.new("utf-8", "0.9")
16+
low = subject.new("iso-8859-1", "0.5")
17+
expect(high <=> low).to be == -1
18+
end
1319
end
1420

1521
describe Protocol::HTTP::Header::AcceptCharset do

‎test/protocol/http/header/accept_encoding.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
encoding = subject.new("utf-8", nil)
1111
expect(encoding.quality_factor).to be == 1.0
1212
end
13+
14+
it "compares by quality factor" do
15+
high = subject.new("gzip", "0.9")
16+
low = subject.new("deflate", "0.5")
17+
expect(high <=> low).to be == -1
18+
end
1319
end
1420

1521
describe Protocol::HTTP::Header::AcceptEncoding do

‎test/protocol/http/header/accept_language.rb‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
language = subject.new("utf-8", nil)
1111
expect(language.quality_factor).to be == 1.0
1212
end
13+
14+
it "compares by quality factor" do
15+
high = subject.new("en", "0.9")
16+
low = subject.new("fr", "0.5")
17+
expect(high <=> low).to be == -1
18+
end
1319
end
1420

1521
describe Protocol::HTTP::Header::AcceptLanguage do

0 commit comments

Comments
 (0)