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