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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2023-2025, by Samuel Williams.
# Copyright, 2023, by Thomas Morgan.
require "protocol/http/header/cache_control"
describe Protocol::HTTP::Header::CacheControl do
let(:header) {subject.new(description)}
with "max-age=60, s-maxage=30, public" do
it "correctly parses cache header" do
expect(header).to have_attributes(
public?: be == true,
private?: be == false,
max_age: be == 60,
s_maxage: be == 30,
)
end
end
with "max-age=-10, s-maxage=0x22" do
it "gracefully handles invalid values" do
expect(header).to have_attributes(
max_age: be == nil,
s_maxage: be == nil,
)
end
end
with "no-cache, no-store" do
it "correctly parses cache header" do
expect(header).to have_attributes(
no_cache?: be == true,
no_store?: be == true,
)
end
end
with "static" do
it "correctly parses cache header" do
expect(header).to have_attributes(
static?: be == true,
)
end
end
with "dynamic" do
it "correctly parses cache header" do
expect(header).to have_attributes(
dynamic?: be == true,
)
end
end
with "streaming" do
it "correctly parses cache header" do
expect(header).to have_attributes(
streaming?: be == true,
)
end
end
with "must-revalidate" do
it "correctly parses cache header" do
expect(header).to have_attributes(
must_revalidate?: be == true,
)
end
end
with "proxy-revalidate" do
it "correctly parses cache header" do
expect(header).to have_attributes(
proxy_revalidate?: be == true,
)
end
end
with "#<<" do
let(:header) {subject.new}
it "can append values" do
header << "max-age=60"
expect(header).to have_attributes(
max_age: be == 60,
)
end
end
end
|