Skip to content

Commit bc99dbc

Browse files
committed
Improve test organization.
1 parent c649e81 commit bc99dbc

File tree

2 files changed

+59
-63
lines changed

2 files changed

+59
-63
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

0 commit comments

Comments
 (0)