Skip to content

Commit 5cf6df9

Browse files
authored
Remove incorrect uses of describe (#14757)
Fixes a small number of specs which pass both the class name and the method name as separate arguments to `describe`. But it doesn't work like that and the second argument is treated as a file name instead.
1 parent 912970c commit 5cf6df9

File tree

2 files changed

+349
-345
lines changed

2 files changed

+349
-345
lines changed

spec/std/benchmark_spec.cr

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -34,81 +34,83 @@ private def create_entry
3434
Benchmark::IPS::Entry.new("label", ->{ 1 + 1 })
3535
end
3636

37-
describe Benchmark::IPS::Entry, "#set_cycles" do
38-
it "sets the number of cycles needed to make 100ms" do
39-
e = create_entry
40-
e.set_cycles(2.seconds, 100)
41-
e.cycles.should eq(5)
42-
43-
e.set_cycles(100.milliseconds, 1)
44-
e.cycles.should eq(1)
45-
end
46-
47-
it "sets the cycles to 1 no matter what" do
48-
e = create_entry
49-
e.set_cycles(2.seconds, 1)
50-
e.cycles.should eq(1)
51-
end
37+
private def h_mean(mean)
38+
create_entry.tap { |e| e.mean = mean }.human_mean
5239
end
5340

54-
describe Benchmark::IPS::Entry, "#calculate_stats" do
55-
it "correctly calculates basic stats" do
56-
e = create_entry
57-
e.calculate_stats([2, 4, 4, 4, 5, 5, 7, 9])
41+
private def h_ips(seconds)
42+
mean = 1.0 / seconds
43+
create_entry.tap { |e| e.mean = mean }.human_iteration_time
44+
end
5845

59-
e.size.should eq(8)
60-
e.mean.should eq(5.0)
61-
e.variance.should eq(4.0)
62-
e.stddev.should eq(2.0)
46+
describe Benchmark::IPS::Entry do
47+
describe "#set_cycles" do
48+
it "sets the number of cycles needed to make 100ms" do
49+
e = create_entry
50+
e.set_cycles(2.seconds, 100)
51+
e.cycles.should eq(5)
52+
53+
e.set_cycles(100.milliseconds, 1)
54+
e.cycles.should eq(1)
55+
end
56+
57+
it "sets the cycles to 1 no matter what" do
58+
e = create_entry
59+
e.set_cycles(2.seconds, 1)
60+
e.cycles.should eq(1)
61+
end
6362
end
64-
end
6563

66-
private def h_mean(mean)
67-
create_entry.tap { |e| e.mean = mean }.human_mean
68-
end
64+
describe "#calculate_stats" do
65+
it "correctly calculates basic stats" do
66+
e = create_entry
67+
e.calculate_stats([2, 4, 4, 4, 5, 5, 7, 9])
6968

70-
describe Benchmark::IPS::Entry, "#human_mean" do
71-
it { h_mean(0.01234567890123).should eq(" 12.35m") }
72-
it { h_mean(0.12345678901234).should eq("123.46m") }
69+
e.size.should eq(8)
70+
e.mean.should eq(5.0)
71+
e.variance.should eq(4.0)
72+
e.stddev.should eq(2.0)
73+
end
74+
end
7375

74-
it { h_mean(1.23456789012345).should eq(" 1.23 ") }
75-
it { h_mean(12.3456789012345).should eq(" 12.35 ") }
76-
it { h_mean(123.456789012345).should eq("123.46 ") }
76+
describe "#human_mean" do
77+
it { h_mean(0.01234567890123).should eq(" 12.35m") }
78+
it { h_mean(0.12345678901234).should eq("123.46m") }
7779

78-
it { h_mean(1234.56789012345).should eq(" 1.23k") }
79-
it { h_mean(12345.6789012345).should eq(" 12.35k") }
80-
it { h_mean(123456.789012345).should eq("123.46k") }
80+
it { h_mean(1.23456789012345).should eq(" 1.23 ") }
81+
it { h_mean(12.3456789012345).should eq(" 12.35 ") }
82+
it { h_mean(123.456789012345).should eq("123.46 ") }
8183

82-
it { h_mean(1234567.89012345).should eq(" 1.23M") }
83-
it { h_mean(12345678.9012345).should eq(" 12.35M") }
84-
it { h_mean(123456789.012345).should eq("123.46M") }
84+
it { h_mean(1234.56789012345).should eq(" 1.23k") }
85+
it { h_mean(12345.6789012345).should eq(" 12.35k") }
86+
it { h_mean(123456.789012345).should eq("123.46k") }
8587

86-
it { h_mean(1234567890.12345).should eq(" 1.23G") }
87-
it { h_mean(12345678901.2345).should eq(" 12.35G") }
88-
it { h_mean(123456789012.345).should eq("123.46G") }
89-
end
88+
it { h_mean(1234567.89012345).should eq(" 1.23M") }
89+
it { h_mean(12345678.9012345).should eq(" 12.35M") }
90+
it { h_mean(123456789.012345).should eq("123.46M") }
9091

91-
private def h_ips(seconds)
92-
mean = 1.0 / seconds
93-
create_entry.tap { |e| e.mean = mean }.human_iteration_time
94-
end
92+
it { h_mean(1234567890.12345).should eq(" 1.23G") }
93+
it { h_mean(12345678901.2345).should eq(" 12.35G") }
94+
it { h_mean(123456789012.345).should eq("123.46G") }
95+
end
9596

96-
describe Benchmark::IPS::Entry, "#human_iteration_time" do
97-
it { h_ips(1234.567_890_123).should eq("1,234.57s ") }
98-
it { h_ips(123.456_789_012_3).should eq("123.46s ") }
99-
it { h_ips(12.345_678_901_23).should eq(" 12.35s ") }
100-
it { h_ips(1.234_567_890_123).should eq(" 1.23s ") }
97+
describe "#human_iteration_time" do
98+
it { h_ips(1234.567_890_123).should eq("1,234.57s ") }
99+
it { h_ips(123.456_789_012_3).should eq("123.46s ") }
100+
it { h_ips(12.345_678_901_23).should eq(" 12.35s ") }
101+
it { h_ips(1.234_567_890_123).should eq(" 1.23s ") }
101102

102-
it { h_ips(0.123_456_789_012).should eq("123.46ms") }
103-
it { h_ips(0.012_345_678_901).should eq(" 12.35ms") }
104-
it { h_ips(0.001_234_567_890).should eq(" 1.23ms") }
103+
it { h_ips(0.123_456_789_012).should eq("123.46ms") }
104+
it { h_ips(0.012_345_678_901).should eq(" 12.35ms") }
105+
it { h_ips(0.001_234_567_890).should eq(" 1.23ms") }
105106

106-
it { h_ips(0.000_123_456_789).should eq("123.46µs") }
107-
it { h_ips(0.000_012_345_678).should eq(" 12.35µs") }
108-
it { h_ips(0.000_001_234_567).should eq(" 1.23µs") }
107+
it { h_ips(0.000_123_456_789).should eq("123.46µs") }
108+
it { h_ips(0.000_012_345_678).should eq(" 12.35µs") }
109+
it { h_ips(0.000_001_234_567).should eq(" 1.23µs") }
109110

110-
it { h_ips(0.000_000_123_456).should eq("123.46ns") }
111-
it { h_ips(0.000_000_012_345).should eq(" 12.34ns") }
112-
it { h_ips(0.000_000_001_234).should eq(" 1.23ns") }
113-
it { h_ips(0.000_000_000_123).should eq(" 0.12ns") }
111+
it { h_ips(0.000_000_123_456).should eq("123.46ns") }
112+
it { h_ips(0.000_000_012_345).should eq(" 12.34ns") }
113+
it { h_ips(0.000_000_001_234).should eq(" 1.23ns") }
114+
it { h_ips(0.000_000_000_123).should eq(" 0.12ns") }
115+
end
114116
end

0 commit comments

Comments
 (0)