ruby-metrics 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-metrics (0.8.5)
4
+ ruby-metrics (0.8.6)
5
5
  json
6
6
 
7
7
  GEM
@@ -36,7 +36,7 @@ module Metrics
36
36
  end
37
37
 
38
38
  def self.to_json
39
- @instruments.to_json
39
+ @instruments.to_json
40
40
  end
41
41
 
42
42
  module TypeMethods
@@ -6,10 +6,14 @@ module Metrics
6
6
  raise NotImplementedError
7
7
  end
8
8
 
9
- def to_s
9
+ def to_json(*_)
10
10
  raise NotImplementedError
11
11
  end
12
12
 
13
+ def to_s
14
+ self.to_json
15
+ end
16
+
13
17
  def to_f
14
18
  raise NotImplementedError
15
19
  end
@@ -24,7 +24,7 @@ module Metrics
24
24
  @value.to_i
25
25
  end
26
26
 
27
- def to_s
27
+ def to_json(*_)
28
28
  @value.to_s
29
29
  end
30
30
 
@@ -11,7 +11,7 @@ module Metrics
11
11
  instance_exec(&@block)
12
12
  end
13
13
 
14
- def to_s
14
+ def to_json(*_)
15
15
  get.to_json
16
16
  end
17
17
 
@@ -149,7 +149,7 @@ module Metrics
149
149
  @sample.values
150
150
  end
151
151
 
152
- def to_s
152
+ def to_json(*_)
153
153
  {
154
154
  :min => self.min,
155
155
  :max => self.max,
@@ -84,7 +84,7 @@ module Metrics
84
84
  end
85
85
  end
86
86
 
87
- def to_s
87
+ def to_json(*_)
88
88
  {
89
89
  :one_minute_rate => self.one_minute_rate,
90
90
  :five_minute_rate => self.five_minute_rate,
@@ -98,7 +98,7 @@ module Metrics
98
98
  end
99
99
  end
100
100
 
101
- def to_s
101
+ def to_json(*_)
102
102
  {
103
103
  :count => self.count,
104
104
  :rates => {
@@ -1,3 +1,3 @@
1
1
  module Metrics
2
- VERSION = "0.8.5"
2
+ VERSION = "0.8.6"
3
3
  end
@@ -5,7 +5,7 @@ describe Metrics::Instruments::Base do
5
5
  @base = Metrics::Instruments::Base.new
6
6
  end
7
7
 
8
- %w( to_i to_f to_s ).each do |method|
8
+ %w( to_i to_f to_json to_s ).each do |method|
9
9
  it "should raise a NotImplementedError for ##{method}" do
10
10
  lambda do
11
11
  @base.send(method)
@@ -69,4 +69,11 @@ describe Metrics::Instruments::Counter do
69
69
  end.should change{ @counter.to_i }.by(-1)
70
70
  end
71
71
 
72
+ context "to_json" do
73
+ let(:json) { @counter.to_json }
74
+ it "should serialize to its current value" do
75
+ json.should == @counter.to_s
76
+ end
77
+ end
78
+
72
79
  end
@@ -27,18 +27,16 @@ describe Metrics::Instruments::Gauge do
27
27
  @gauge.get[:result].should == 43
28
28
  end
29
29
 
30
- it "should JSONify the results when you call to_s" do
31
- result = 42
32
-
33
- callback = Proc.new do
34
- {
35
- :result => result
36
- }
30
+ context "to_json" do
31
+ it "should serialize the current value" do
32
+ result = 0
33
+ gauge = Metrics::Instruments::Gauge.new{ result }
34
+
35
+ gauge.to_json.should == result.to_s
36
+
37
+ result = 2
38
+ gauge.to_json.should == result.to_s
37
39
  end
38
-
39
- @gauge = Metrics::Instruments::Gauge.new &callback
40
-
41
- @gauge.to_s.should == "{\"result\":42}"
42
40
  end
43
41
 
44
42
  end
@@ -39,10 +39,6 @@ describe Metrics::Instruments::Histogram do
39
39
  @histogram.mean.should == 3.4877830882352936
40
40
  end
41
41
 
42
- it "should accurately represent itself using JSON" do
43
- @histogram.to_s.should == "{\"min\":1.6,\"max\":5.1,\"mean\":3.4877830882352936,\"variance\":1.3027283328494685,\"percentiles\":{\"0.25\":2.16275,\"0.5\":4.0,\"0.75\":4.45425,\"0.95\":4.817,\"0.97\":4.8977900000000005,\"0.98\":4.933,\"0.99\":5.009570000000001}}"
44
- end
45
-
46
42
  it "should return correct values for mean, std. deviation and variance when no elements are in the histogram" do
47
43
  histogram = Metrics::Instruments::Histogram.new
48
44
  histogram.variance.should == 0.0
@@ -96,4 +92,24 @@ describe Metrics::Instruments::Histogram do
96
92
  end
97
93
  end
98
94
 
95
+ context "to_json" do
96
+ before(:each) do
97
+ @histogram = Metrics::Instruments::Histogram.new
98
+ @hash = JSON.parse(@histogram.to_json)
99
+ end
100
+
101
+ %w( min max mean variance ).each do |attr|
102
+ it "should serialize with the #{attr} value" do
103
+ @hash[attr].should_not be_nil
104
+ end
105
+ end
106
+
107
+ %w( 0.25 0.5 0.75 0.95 0.97 0.98 0.99 ).each do |percentile|
108
+ it "should have the #{percentile} percentile" do
109
+ @hash["percentiles"][percentile].should_not be_nil
110
+ end
111
+ end
112
+
113
+ end
114
+
99
115
  end
@@ -81,6 +81,19 @@ describe Metrics::Instruments::Meter do
81
81
  end
82
82
 
83
83
  end
84
+
85
+ context "to_json" do
86
+ before(:each) do
87
+ @meter = Metrics::Instruments::Meter.new
88
+ @hash = JSON.parse(@meter.to_json)
89
+ end
90
+
91
+ %w( one_minute_rate five_minute_rate fifteen_minute_rate ).each do |attr|
92
+ it "should serialize with the #{attr} value" do
93
+ @hash[attr].should_not be_nil
94
+ end
95
+ end
84
96
 
97
+ end
85
98
 
86
- end
99
+ end
@@ -92,9 +92,6 @@ describe Metrics::Instruments::Timer do
92
92
  @timer.values.sort.should == [10, 20, 20, 30, 40]
93
93
  end
94
94
 
95
- it "should accurately represent itself using JSON" do
96
- @timer.to_s.should == "{\"count\":5,\"rates\":{\"one_minute_rate\":0.0,\"five_minute_rate\":0.0,\"fifteen_minute_rate\":0.0,\"unit\":\"seconds\"},\"durations\":{\"min\":10.0,\"max\":40.0,\"mean\":24.0,\"percentiles\":{\"0.25\":20.0,\"0.5\":20.0,\"0.75\":30.0,\"0.95\":38.0,\"0.97\":38.8,\"0.98\":39.2,\"0.99\":39.6},\"unit\":\"milliseconds\"}}"
97
- end
98
95
  end
99
96
 
100
97
  context "Timing blocks of code" do
@@ -116,4 +113,34 @@ describe Metrics::Instruments::Timer do
116
113
  end
117
114
  end
118
115
 
116
+ context "to_json" do
117
+ before(:each) do
118
+ @timer = Metrics::Instruments::Timer.new
119
+ @hash = JSON.parse(@timer.to_json)
120
+ end
121
+
122
+ it "should serialize with the count value" do
123
+ @hash["count"].should_not be_nil
124
+ end
125
+
126
+ %w( one_minute_rate five_minute_rate fifteen_minute_rate ).each do |rate|
127
+ it "should serialize with the #{rate} rate" do
128
+ @hash["rates"][rate].should_not be_nil
129
+ end
130
+ end
131
+
132
+ %w( min max mean ).each do |duration|
133
+ it "should serialize with the #{duration} duration" do
134
+ @hash["durations"][duration].should_not be_nil
135
+ end
136
+ end
137
+
138
+ %w( 0.25 0.5 0.75 0.95 0.97 0.98 0.99 ).each do |percentile|
139
+ it "should serialize with the #{percentile} duration percentile" do
140
+ @hash["durations"]["percentiles"][percentile].should_not be_nil
141
+ end
142
+ end
143
+
144
+ end
145
+
119
146
  end
@@ -45,7 +45,7 @@ describe Metrics::Instruments do
45
45
  @instruments.register(:meter, :test_meter).should == @meter
46
46
  @instruments.registered.should == {:test_meter => @meter}
47
47
 
48
- @instruments.to_json.should == "{\"test_meter\":\"{\\\"one_minute_rate\\\":0.0,\\\"five_minute_rate\\\":0.0,\\\"fifteen_minute_rate\\\":0.0}\"}"
48
+ @instruments.to_json.should == %({"test_meter":{"one_minute_rate":0.0,"five_minute_rate":0.0,"fifteen_minute_rate":0.0}})
49
49
  end
50
50
 
51
51
  it "should not allow for creating a gauge with no block" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 5
9
- version: 0.8.5
8
+ - 6
9
+ version: 0.8.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - John Ewart
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-11 00:00:00 -07:00
17
+ date: 2011-06-02 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
- hash: -317001895156670469
151
+ hash: -4510992277753869263
152
152
  segments:
153
153
  - 0
154
154
  version: "0"
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- hash: -317001895156670469
160
+ hash: -4510992277753869263
161
161
  segments:
162
162
  - 0
163
163
  version: "0"