/
data_spec.rb
84 lines (72 loc) · 2.34 KB
/
data_spec.rb
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
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe SimpleStatistics::Data do
describe "collection" do
before :each do
@data = SimpleStatistics::Data.new
end
it "should accept probes with #add_probe" do
lambda {
@data.tick(:default)
@data.add_probe(:default, 1)
}.should_not raise_error
end
describe "accessed with proxy" do
describe "with some probes" do
before :each do
@now = Time.now
100.times do |i|
Timecop.freeze(@now+i)
@data.tick(:default)
@data[:default].add_probe(i)
end
Timecop.return
end
describe "on call #last_probes_by_count with 3 probes" do
before :each do
@sample = @data[:default].last_probes_by_count(3)
end
it "should return Sample with correct data" do
@sample.data.should == [97,98,99]
end
end
describe "on call #last_probes_by_time with Time.now - 10.seconds probes" do
before :each do
@sample = @data[:default].last_probes_by_time(@now + 100 - 10)
end
it "should return Sample with correct data" do
@sample.data.should == [90,91,92,93,94,95,96,97,98,99]
end
end
end
end
describe "accessed without proxy" do
describe "with some probes" do
before :each do
@now = Time.now
100.times do |i|
Timecop.freeze(@now+i)
@data.tick(:default)
@data.add_probe(:default, i)
end
Timecop.return
end
describe "on call #last_probes_by_count with 3 probes" do
before :each do
@sample = @data.last_probes_by_count(:default, 3)
end
it "should return Sample with correct data" do
@sample.data.should == [97,98,99]
end
end
describe "on call #last_probes_by_time with Time.now - 10.seconds probes" do
before :each do
@sample = @data.last_probes_by_time(:default, @now + 100 - 10)
end
it "should return Sample with correct data" do
@sample.data.should == [90,91,92,93,94,95,96,97,98,99]
end
end
end
end
end
end