Skip to content

Commit 7c3fa21

Browse files
committed
Improve test organization.
1 parent c649e81 commit 7c3fa21

File tree

3 files changed

+87
-91
lines changed

3 files changed

+87
-91
lines changed

test/protocol/http/header/digest.rb

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -118,33 +118,6 @@
118118
end
119119
end
120120

121-
with "Entry class" do
122-
let(:entry_class) {subject::Entry}
123-
124-
it "can create entry directly" do
125-
entry = entry_class.new("sha-256", "abc123")
126-
expect(entry.algorithm).to be == "sha-256"
127-
expect(entry.value).to be == "abc123"
128-
expect(entry.to_s).to be == "sha-256=abc123"
129-
end
130-
131-
it "normalizes algorithm to lowercase" do
132-
entry = entry_class.new("SHA-256", "abc123")
133-
expect(entry.algorithm).to be == "sha-256"
134-
end
135-
136-
it "handles complex algorithm names" do
137-
entry = entry_class.new("sha-384", "complex-value")
138-
expect(entry.algorithm).to be == "sha-384"
139-
expect(entry.to_s).to be == "sha-384=complex-value"
140-
end
141-
142-
it "handles base64 padding in values" do
143-
entry = entry_class.new("md5", "abc123==")
144-
expect(entry.value).to be == "abc123=="
145-
end
146-
end
147-
148121
with "algorithm edge cases" do
149122
it "handles hyphenated algorithms" do
150123
header = subject.new("sha-256=abc123")
@@ -158,7 +131,7 @@
158131
expect(entries.first.algorithm).to be == "md5"
159132
end
160133
end
161-
134+
162135
with "value edge cases" do
163136
it "handles empty values" do
164137
header = subject.new("sha-256=")
@@ -172,4 +145,29 @@
172145
expect(entries.first.value).to be == "abc+def/123=="
173146
end
174147
end
175-
end
148+
end
149+
150+
describe Protocol::HTTP::Header::Digest::Entry do
151+
it "can create entry directly" do
152+
entry = subject.new("sha-256", "abc123")
153+
expect(entry.algorithm).to be == "sha-256"
154+
expect(entry.value).to be == "abc123"
155+
expect(entry.to_s).to be == "sha-256=abc123"
156+
end
157+
158+
it "normalizes algorithm to lowercase" do
159+
entry = subject.new("SHA-256", "abc123")
160+
expect(entry.algorithm).to be == "sha-256"
161+
end
162+
163+
it "handles complex algorithm names" do
164+
entry = subject.new("sha-384", "complex-value")
165+
expect(entry.algorithm).to be == "sha-384"
166+
expect(entry.to_s).to be == "sha-384=complex-value"
167+
end
168+
169+
it "handles base64 padding in values" do
170+
entry = subject.new("md5", "abc123==")
171+
expect(entry.value).to be == "abc123=="
172+
end
173+
end

test/protocol/http/header/server_timing.rb

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -213,39 +213,37 @@
213213
expect(metrics.first.duration).to be == 123.456789
214214
end
215215
end
216+
end
217+
218+
describe Protocol::HTTP::Header::ServerTiming::Metric do
219+
it "can create metric directly" do
220+
metric = subject.new("test", 123.45, "Test metric")
221+
expect(metric.name).to be == "test"
222+
expect(metric.duration).to be == 123.45
223+
expect(metric.description).to be == "Test metric"
224+
expect(metric.to_s).to be == "test;dur=123.45;desc=\"Test metric\""
225+
end
216226

217-
with "Metric class" do
218-
let(:metric_class) {subject::Metric}
219-
220-
it "can create metric directly" do
221-
metric = metric_class.new("test", 123.45, "Test metric")
222-
expect(metric.name).to be == "test"
223-
expect(metric.duration).to be == 123.45
224-
expect(metric.description).to be == "Test metric"
225-
expect(metric.to_s).to be == "test;dur=123.45;desc=\"Test metric\""
226-
end
227-
228-
it "can create metric with name only" do
229-
metric = metric_class.new("cache")
230-
expect(metric.name).to be == "cache"
231-
expect(metric.duration).to be_nil
232-
expect(metric.description).to be_nil
233-
expect(metric.to_s).to be == "cache"
234-
end
235-
236-
it "can create metric with duration only" do
237-
metric = metric_class.new("test", 123.45, nil)
238-
expect(metric.to_s).to be == "test;dur=123.45"
239-
end
240-
241-
it "can create metric with description only" do
242-
metric = metric_class.new("test", nil, "description")
243-
expect(metric.to_s).to be == "test;desc=\"description\""
244-
end
245-
246-
it "handles nil values correctly" do
247-
metric = metric_class.new("test", nil, nil)
248-
expect(metric.to_s).to be == "test"
249-
end
227+
it "can create metric with name only" do
228+
metric = subject.new("cache")
229+
expect(metric.name).to be == "cache"
230+
expect(metric.duration).to be_nil
231+
expect(metric.description).to be_nil
232+
expect(metric.to_s).to be == "cache"
233+
end
234+
235+
it "can create metric with duration only" do
236+
metric = subject.new("test", 123.45, nil)
237+
expect(metric.to_s).to be == "test;dur=123.45"
238+
end
239+
240+
it "can create metric with description only" do
241+
metric = subject.new("test", nil, "description")
242+
expect(metric.to_s).to be == "test;desc=\"description\""
243+
end
244+
245+
it "handles nil values correctly" do
246+
metric = subject.new("test", nil, nil)
247+
expect(metric.to_s).to be == "test"
250248
end
251-
end
249+
end

test/protocol/http/header/te.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -98,37 +98,37 @@
9898
end
9999
end
100100

101-
with "TransferCoding struct" do
102-
it "handles quality factor conversion" do
103-
coding = Protocol::HTTP::Header::TE::TransferCoding.new("gzip", "0.8")
104-
expect(coding.quality_factor).to be == 0.8
105-
end
106-
107-
it "defaults quality factor to 1.0" do
108-
coding = Protocol::HTTP::Header::TE::TransferCoding.new("gzip", nil)
109-
expect(coding.quality_factor).to be == 1.0
110-
end
111-
112-
it "serializes with quality factor" do
113-
coding = Protocol::HTTP::Header::TE::TransferCoding.new("gzip", "0.8")
114-
expect(coding.to_s).to be == "gzip;q=0.8"
115-
end
116-
117-
it "serializes without quality factor when 1.0" do
118-
coding = Protocol::HTTP::Header::TE::TransferCoding.new("gzip", nil)
119-
expect(coding.to_s).to be == "gzip"
120-
end
121-
122-
it "compares by quality factor" do
123-
high = Protocol::HTTP::Header::TE::TransferCoding.new("gzip", "0.9")
124-
low = Protocol::HTTP::Header::TE::TransferCoding.new("deflate", "0.5")
125-
expect(high <=> low).to be == -1 # high quality first
126-
end
127-
end
128-
129101
with ".trailer?" do
130102
it "should be forbidden in trailers" do
131103
expect(subject).not.to be(:trailer?)
132104
end
133105
end
106+
end
107+
108+
describe Protocol::HTTP::Header::TE::TransferCoding do
109+
it "handles quality factor conversion" do
110+
coding = subject.new("gzip", "0.8")
111+
expect(coding.quality_factor).to be == 0.8
112+
end
113+
114+
it "defaults quality factor to 1.0" do
115+
coding = subject.new("gzip", nil)
116+
expect(coding.quality_factor).to be == 1.0
117+
end
118+
119+
it "serializes with quality factor" do
120+
coding = subject.new("gzip", "0.8")
121+
expect(coding.to_s).to be == "gzip;q=0.8"
122+
end
123+
124+
it "serializes without quality factor when 1.0" do
125+
coding = subject.new("gzip", nil)
126+
expect(coding.to_s).to be == "gzip"
127+
end
128+
129+
it "compares by quality factor" do
130+
high = subject.new("gzip", "0.9")
131+
low = subject.new("deflate", "0.5")
132+
expect(high <=> low).to be == -1 # high quality first
133+
end
134134
end

0 commit comments

Comments
 (0)