pulse_meter_core 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,11 +19,11 @@ describe PulseMeter::Observer::Extended do
19
19
 
20
20
  dummy.incr(40)
21
21
 
22
- parameters[:self].should == dummy
23
- parameters[:delta].should >= 1000
24
- parameters[:result].should == 40
25
- parameters[:exception].should be_nil
26
- parameters[:args].should == [40]
22
+ expect(parameters[:self]).to eq(dummy)
23
+ expect(parameters[:delta]).to be >= 1000
24
+ expect(parameters[:result]).to eq(40)
25
+ expect(parameters[:exception]).to be_nil
26
+ expect(parameters[:args]).to eq([40])
27
27
  end
28
28
  end
29
29
 
@@ -35,12 +35,12 @@ describe PulseMeter::Observer::Extended do
35
35
  parameters = params
36
36
  end
37
37
 
38
- lambda { dummy.error }.should raise_error(RuntimeError)
38
+ expect { dummy.error }.to raise_error(RuntimeError)
39
39
 
40
- parameters[:self].should == dummy
41
- parameters[:result].should == nil
42
- parameters[:exception].class.should == RuntimeError
43
- parameters[:args].should == []
40
+ expect(parameters[:self]).to eq(dummy)
41
+ expect(parameters[:result]).to eq(nil)
42
+ expect(parameters[:exception].class).to eq(RuntimeError)
43
+ expect(parameters[:args]).to eq([])
44
44
  end
45
45
  end
46
46
  end
@@ -63,11 +63,11 @@ describe PulseMeter::Observer::Extended do
63
63
 
64
64
  ObservedDummy.incr(40)
65
65
 
66
- parameters[:self].should == ObservedDummy
67
- parameters[:delta].should >= 1000
68
- parameters[:result].should == 40
69
- parameters[:exception].should be_nil
70
- parameters[:args].should == [40]
66
+ expect(parameters[:self]).to eq(ObservedDummy)
67
+ expect(parameters[:delta]).to be >= 1000
68
+ expect(parameters[:result]).to eq(40)
69
+ expect(parameters[:exception]).to be_nil
70
+ expect(parameters[:args]).to eq([40])
71
71
  end
72
72
  end
73
73
 
@@ -79,12 +79,12 @@ describe PulseMeter::Observer::Extended do
79
79
  parameters = params
80
80
  end
81
81
 
82
- lambda { ObservedDummy.error }.should raise_error(RuntimeError)
82
+ expect { ObservedDummy.error }.to raise_error(RuntimeError)
83
83
 
84
- parameters[:self].should == ObservedDummy
85
- parameters[:result].should == nil
86
- parameters[:exception].class.should == RuntimeError
87
- parameters[:args].should == []
84
+ expect(parameters[:self]).to eq(ObservedDummy)
85
+ expect(parameters[:result]).to eq(nil)
86
+ expect(parameters[:exception].class).to eq(RuntimeError)
87
+ expect(parameters[:args]).to eq([])
88
88
  end
89
89
  end
90
90
  end
@@ -23,13 +23,13 @@ describe PulseMeter::Observer do
23
23
  it "executes block in context of sensor each time specified method of given class called" do
24
24
  create_observer
25
25
  5.times {dummy.incr}
26
- sensor.value.should == 5
26
+ expect(sensor.value).to eq(5)
27
27
  end
28
28
 
29
29
  it "passes arguments to observed method" do
30
30
  create_observer
31
31
  5.times {dummy.incr(10)}
32
- dummy.count.should == 50
32
+ expect(dummy.count).to eq(50)
33
33
  end
34
34
 
35
35
  it "passes methods' params to block" do
@@ -38,7 +38,7 @@ describe PulseMeter::Observer do
38
38
  end
39
39
 
40
40
  5.times {dummy.incr(10)}
41
- sensor.value.should == 50
41
+ expect(sensor.value).to eq(50)
42
42
  end
43
43
 
44
44
  it "passes execution time in milliseconds to block" do
@@ -48,7 +48,7 @@ describe PulseMeter::Observer do
48
48
  end
49
49
 
50
50
  dummy.incr
51
- sensor.value.should >= 1000
51
+ expect(sensor.value).to be >= 1000
52
52
  end
53
53
  end
54
54
 
@@ -57,26 +57,26 @@ describe PulseMeter::Observer do
57
57
  raise RuntimeError
58
58
  end
59
59
 
60
- lambda {dummy.incr}.should_not raise_error
61
- dummy.count.should == 1
60
+ expect {dummy.incr}.not_to raise_error
61
+ expect(dummy.count).to eq(1)
62
62
  end
63
63
 
64
64
  it "uses first observer in case of double observation" do
65
65
  create_observer(:incr, 1)
66
66
  create_observer(:incr, 2)
67
67
  5.times {dummy.incr}
68
- sensor.value.should == 5
68
+ expect(sensor.value).to eq(5)
69
69
  end
70
70
 
71
71
  it "keeps observed methods' errors" do
72
72
  create_observer(:error)
73
- lambda {dummy.error}.should raise_error
74
- sensor.value.should == 1
73
+ expect {dummy.error}.to raise_error
74
+ expect(sensor.value).to eq(1)
75
75
  end
76
76
 
77
77
  it "makes observed method return its value" do
78
78
  create_observer
79
- dummy.incr.should == 1
79
+ expect(dummy.incr).to eq(1)
80
80
  end
81
81
 
82
82
  it "allows to pass blocks to observed method" do
@@ -84,13 +84,13 @@ describe PulseMeter::Observer do
84
84
  dummy.incr do
85
85
  2
86
86
  end
87
- dummy.count.should == 3
87
+ expect(dummy.count).to eq(3)
88
88
  end
89
89
  end
90
90
 
91
91
  describe ".unobserve_method" do
92
92
  it "does nothing unless method is observed" do
93
- lambda {remove_observer}.should_not raise_error
93
+ expect {remove_observer}.not_to raise_error
94
94
  end
95
95
 
96
96
  it "removes observation from observed method" do
@@ -98,7 +98,7 @@ describe PulseMeter::Observer do
98
98
  dummy.incr
99
99
  remove_observer
100
100
  dummy.incr
101
- sensor.value.should == 1
101
+ expect(sensor.value).to eq(1)
102
102
  end
103
103
  end
104
104
  end
@@ -125,13 +125,13 @@ describe PulseMeter::Observer do
125
125
  it "executes block in context of sensor each time specified method of given class called" do
126
126
  create_observer
127
127
  5.times {dummy.incr}
128
- sensor.value.should == 5
128
+ expect(sensor.value).to eq(5)
129
129
  end
130
130
 
131
131
  it "passes arguments to observed method" do
132
132
  create_observer
133
133
  5.times {dummy.incr(10)}
134
- dummy.count.should == 50
134
+ expect(dummy.count).to eq(50)
135
135
  end
136
136
 
137
137
  it "passes methods' params to block" do
@@ -140,7 +140,7 @@ describe PulseMeter::Observer do
140
140
  end
141
141
 
142
142
  5.times {dummy.incr(10)}
143
- sensor.value.should == 50
143
+ expect(sensor.value).to eq(50)
144
144
  end
145
145
 
146
146
  it "passes execution time in milliseconds to block" do
@@ -150,7 +150,7 @@ describe PulseMeter::Observer do
150
150
  end
151
151
 
152
152
  dummy.incr
153
- sensor.value.should == 1000
153
+ expect(sensor.value).to eq(1000)
154
154
  end
155
155
  end
156
156
 
@@ -159,26 +159,26 @@ describe PulseMeter::Observer do
159
159
  raise RuntimeError
160
160
  end
161
161
 
162
- lambda {dummy.incr}.should_not raise_error
163
- dummy.count.should == 1
162
+ expect {dummy.incr}.not_to raise_error
163
+ expect(dummy.count).to eq(1)
164
164
  end
165
165
 
166
166
  it "uses first observer in case of double observation" do
167
167
  create_observer(:incr, 1)
168
168
  create_observer(:incr, 2)
169
169
  5.times {dummy.incr}
170
- sensor.value.should == 5
170
+ expect(sensor.value).to eq(5)
171
171
  end
172
172
 
173
173
  it "keeps observed methods' errors" do
174
174
  create_observer(:error)
175
- lambda {dummy.error}.should raise_error
176
- sensor.value.should == 1
175
+ expect {dummy.error}.to raise_error
176
+ expect(sensor.value).to eq(1)
177
177
  end
178
178
 
179
179
  it "makes observed method return its value" do
180
180
  create_observer
181
- dummy.incr.should == 1
181
+ expect(dummy.incr).to eq(1)
182
182
  end
183
183
 
184
184
  it "allows to pass blocks to observed method" do
@@ -186,13 +186,13 @@ describe PulseMeter::Observer do
186
186
  dummy.incr do
187
187
  2
188
188
  end
189
- dummy.count.should == 3
189
+ expect(dummy.count).to eq(3)
190
190
  end
191
191
  end
192
192
 
193
193
  describe ".unobserve_class_method" do
194
194
  it "does nothing unless method is observed" do
195
- lambda {remove_observer}.should_not raise_error
195
+ expect {remove_observer}.not_to raise_error
196
196
  end
197
197
 
198
198
  it "removes observation from observed method" do
@@ -200,7 +200,7 @@ describe PulseMeter::Observer do
200
200
  dummy.incr
201
201
  remove_observer
202
202
  dummy.incr
203
- sensor.value.should == 1
203
+ expect(sensor.value).to eq(1)
204
204
  end
205
205
  end
206
206
  end
@@ -8,7 +8,7 @@ describe PulseMeter::Sensor::Base do
8
8
 
9
9
  describe '#initialize' do
10
10
  context 'when PulseMeter.redis is not initialized' do
11
- it "should raise RedisNotInitialized exception" do
11
+ it "raises RedisNotInitialized exception" do
12
12
  PulseMeter.redis = nil
13
13
  expect{ described_class.new(:foo) }.to raise_exception(PulseMeter::RedisNotInitialized)
14
14
  end
@@ -17,7 +17,7 @@ describe PulseMeter::Sensor::Base do
17
17
  context 'when PulseMeter.redis is initialized' do
18
18
 
19
19
  context 'when passed sensor name is bad' do
20
- it "should raise BadSensorName exception" do
20
+ it "raises BadSensorName exception" do
21
21
  ['name with whitespace', 'name|with|bad|characters'].each do |bad_name|
22
22
  expect{ described_class.new(bad_name) }.to raise_exception(PulseMeter::BadSensorName)
23
23
  end
@@ -25,24 +25,24 @@ describe PulseMeter::Sensor::Base do
25
25
  end
26
26
 
27
27
  context 'when passed sensor name is valid' do
28
- it "should successfully create object" do
29
- described_class.new("foo_@").should_not be_nil
28
+ it "successfully creates object" do
29
+ expect(described_class.new("foo_@")).not_to be_nil
30
30
  end
31
31
 
32
- it "should initialize attributes #redis and #name" do
32
+ it "initializes attributes #redis and #name" do
33
33
  sensor = described_class.new(:foo)
34
- sensor.name.should == 'foo'
35
- sensor.redis.should == PulseMeter.redis
34
+ expect(sensor.name).to eq('foo')
35
+ expect(sensor.redis).to eq(PulseMeter.redis)
36
36
  end
37
37
 
38
- it "should save dump to redis automatically to let the object be restored by name" do
39
- described_class.restore(name).should be_instance_of(described_class)
38
+ it "saves dump to redis automatically to let the object be restored by name" do
39
+ expect(described_class.restore(name)).to be_instance_of(described_class)
40
40
  end
41
41
 
42
- it "should annotate object if annotation given" do
42
+ it "annotates object if annotation given" do
43
43
  described_class.new(:foo, :annotation => "annotation")
44
44
  sensor = described_class.restore(:foo)
45
- sensor.annotation.should == "annotation"
45
+ expect(sensor.annotation).to eq("annotation")
46
46
  end
47
47
  end
48
48
  end
@@ -50,7 +50,7 @@ describe PulseMeter::Sensor::Base do
50
50
 
51
51
  describe '#annotate' do
52
52
 
53
- it "should store sensor annotation in redis" do
53
+ it "stores sensor annotation in redis" do
54
54
  expect {sensor.annotate(description)}.to change{redis.keys('*').count}.by(1)
55
55
  end
56
56
 
@@ -58,47 +58,47 @@ describe PulseMeter::Sensor::Base do
58
58
 
59
59
  describe '#annotation' do
60
60
  context "when sensor was annotated" do
61
- it "should return stored annotation" do
61
+ it "returns stored annotation" do
62
62
  sensor.annotate(description)
63
- sensor.annotation.should == description
63
+ expect(sensor.annotation).to eq(description)
64
64
  end
65
65
  end
66
66
 
67
67
  context "when sensor was not annotated" do
68
- it "should return nil" do
69
- sensor.annotation.should be_nil
68
+ it "returns nil" do
69
+ expect(sensor.annotation).to be_nil
70
70
  end
71
71
  end
72
72
 
73
73
  context "after sensor data was cleaned" do
74
- it "should return nil" do
74
+ it "returns nil" do
75
75
  sensor.annotate(description)
76
76
  sensor.cleanup
77
- sensor.annotation.should be_nil
77
+ expect(sensor.annotation).to be_nil
78
78
  end
79
79
  end
80
80
  end
81
81
 
82
82
  describe "#cleanup" do
83
- it "should remove from redis all sensor data" do
83
+ it "removes from redis all sensor data" do
84
84
  sensor.event(123)
85
85
  sensor.annotate(description)
86
86
  sensor.cleanup
87
- redis.keys('*').should be_empty
87
+ expect(redis.keys('*')).to be_empty
88
88
  end
89
89
  end
90
90
 
91
91
  describe "#event" do
92
92
  context "when everything is ok" do
93
- it "should do nothing and return true" do
94
- sensor.event(nil).should be
93
+ it "does nothing and return true" do
94
+ expect(sensor.event(nil)).to be
95
95
  end
96
96
  end
97
97
 
98
98
  context "when an error occures while processing event" do
99
- it "should catch StandardErrors and return false" do
100
- sensor.stub(:process_event) {raise StandardError}
101
- sensor.event(nil).should_not be
99
+ it "catches StandardErrors and return false" do
100
+ allow(sensor).to receive(:process_event) {raise StandardError}
101
+ expect(sensor.event(nil)).not_to be
102
102
  end
103
103
  end
104
104
  end
@@ -15,43 +15,43 @@ describe PulseMeter::Sensor::Configuration do
15
15
  describe "#add_sensor" do
16
16
  let(:cfg) {described_class.new}
17
17
 
18
- it "should create sensor available under passed name" do
19
- cfg.has_sensor?(:foo).should_not be
18
+ it "creates sensor available under passed name" do
19
+ expect(cfg.has_sensor?(:foo)).not_to be
20
20
  cfg.add_sensor(:foo, sensor_type: 'counter')
21
- cfg.has_sensor?(:foo).should_not be
21
+ expect(cfg.has_sensor?(:foo)).not_to be
22
22
  end
23
23
 
24
- it "should have event shortcut for the sensor" do
24
+ it "has event shortcut for the sensor" do
25
25
  cfg.add_sensor(:foo, sensor_type: 'counter')
26
26
  puts cfg.to_yaml
27
- cfg.sensor(:foo){|s| s.should_receive(:event).with(321)}
27
+ cfg.sensor(:foo){|s| expect(s).to receive(:event).with(321)}
28
28
  cfg.foo(321)
29
29
  end
30
-
31
- it "should have event_at shortcut for the sensor" do
30
+
31
+ it "has event_at shortcut for the sensor" do
32
32
  cfg.add_sensor(:foo, sensor_type: 'counter')
33
33
  now = Time.now
34
34
  cfg.sensor(:foo) do |sensor|
35
- sensor.should_receive(:event_at).with(now, 321)
35
+ expect(sensor).to receive(:event_at).with(now, 321)
36
36
  end
37
37
  cfg.foo_at(now, 321)
38
38
  end
39
39
 
40
- it "should create sensor with correct type" do
40
+ it "creates sensor with correct type" do
41
41
  cfg.add_sensor(:foo, sensor_type: 'counter')
42
- cfg.sensor(:foo){|s| s.should be_kind_of(PulseMeter::Sensor::Counter)}
42
+ cfg.sensor(:foo){|s| expect(s).to be_kind_of(PulseMeter::Sensor::Counter)}
43
43
  end
44
44
 
45
- it "should not raise exception if sensor type is bad" do
45
+ it "does not raise exception if sensor type is bad" do
46
46
  expect{ cfg.add_sensor(:foo, sensor_type: 'baaaar') }.not_to raise_exception
47
47
  end
48
48
 
49
- it "should pass args to created sensor" do
49
+ it "passes args to created sensor" do
50
50
  cfg.add_sensor(:foo, sensor_type: 'counter', args: {annotation: "My Foo Counter"} )
51
- cfg.sensor(:foo){|s| s.annotation.should == "My Foo Counter" }
51
+ cfg.sensor(:foo){|s| expect(s.annotation).to eq("My Foo Counter") }
52
52
  end
53
53
 
54
- it "should accept hashie-objects" do
54
+ it "accepts hashie-objects" do
55
55
  class Dummy
56
56
  def sensor_type
57
57
  'counter'
@@ -62,12 +62,12 @@ describe PulseMeter::Sensor::Configuration do
62
62
  end
63
63
 
64
64
  cfg.add_sensor(:foo, Dummy.new)
65
- cfg.sensor(:foo){|s| s.annotation.should == "My Foo Counter"}
65
+ cfg.sensor(:foo){|s| expect(s.annotation).to eq("My Foo Counter")}
66
66
  end
67
67
  end
68
68
 
69
69
  describe ".new" do
70
- it "should add passed sensor setting hash using keys as names" do
70
+ it "adds passed sensor setting hash using keys as names" do
71
71
  opts = {
72
72
  cnt: {
73
73
  sensor_type: 'counter'
@@ -79,15 +79,15 @@ describe PulseMeter::Sensor::Configuration do
79
79
  cfg1 = described_class.new(opts)
80
80
  cfg2 = described_class.new
81
81
  opts.each{|k,v| cfg2.add_sensor(k, v)}
82
- cfg1.sensors.to_yaml.should == cfg2.sensors.to_yaml
82
+ expect(cfg1.sensors.to_yaml).to eq(cfg2.sensors.to_yaml)
83
83
  end
84
84
  end
85
85
 
86
86
  describe "#sensor" do
87
- it "should give access to added sensors via block" do
87
+ it "gives access to added sensors via block" do
88
88
  cfg = described_class.new(counter_config)
89
- cfg.sensor(:cnt){ |s| s.annotation.should == "MySensor" }
90
- cfg.sensor("cnt"){ |s| s.annotation.should == "MySensor" }
89
+ cfg.sensor(:cnt){ |s| expect(s.annotation).to eq("MySensor") }
90
+ cfg.sensor("cnt"){ |s| expect(s.annotation).to eq("MySensor") }
91
91
  end
92
92
  end
93
93
 
@@ -97,7 +97,7 @@ describe PulseMeter::Sensor::Configuration do
97
97
  sensors = {}
98
98
  cfg.each {|s| sensors[s.name.to_sym] = s}
99
99
  sensor = cfg.sensor(:cnt){|s| s}
100
- sensors.should == {:cnt => sensor}
100
+ expect(sensors).to eq({:cnt => sensor})
101
101
  end
102
102
  end
103
103
  end