pulse_meter_visualizer 0.4.20 → 0.4.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,16 +57,16 @@ describe PulseMeter::Visualize::Page do
57
57
 
58
58
  describe "#widget_data" do
59
59
 
60
- it "should generate correct data of single widget" do
60
+ it "generates correct data of single widget" do
61
61
  Timecop.freeze(interval_start + 2 * interval - 1) do
62
- page.widget_data(0)[:id].should == 1
63
- page.widget_data(1)[:id].should == 2
62
+ expect(page.widget_data(0)[:id]).to eq(1)
63
+ expect(page.widget_data(1)[:id]).to eq(2)
64
64
  end
65
65
  end
66
66
 
67
- it "should generate correct data of single widget" do
67
+ it "generates correct data of single widget" do
68
68
  Timecop.freeze(interval_start + 2 * interval - 1) do
69
- page.widget_data(0)[:series].should ==
69
+ expect(page.widget_data(0)[:series]).to eq(
70
70
  {
71
71
  data: [
72
72
  [a_sensor.annotation, 12],
@@ -77,7 +77,8 @@ describe PulseMeter::Visualize::Page do
77
77
  {color: b_color}
78
78
  ]
79
79
  }
80
- page.widget_data(1)[:series].should ==
80
+ )
81
+ expect(page.widget_data(1)[:series]).to eq(
81
82
  {
82
83
  titles: [a_sensor.annotation, b_sensor.annotation],
83
84
  rows: [[interval_start.to_i * 1000, 12, 33]],
@@ -86,10 +87,11 @@ describe PulseMeter::Visualize::Page do
86
87
  {color: b_color}
87
88
  ]
88
89
  }
90
+ )
89
91
  end
90
92
 
91
93
  Timecop.freeze(interval_start + 2 * interval - 1) do
92
- page.widget_data(0, timespan: 0)[:series].should ==
94
+ expect(page.widget_data(0, timespan: 0)[:series]).to eq(
93
95
  {
94
96
  data: [
95
97
  [a_sensor.annotation, 12],
@@ -100,7 +102,8 @@ describe PulseMeter::Visualize::Page do
100
102
  {color: b_color}
101
103
  ]
102
104
  }
103
- page.widget_data(1, timespan: 1)[:series].should ==
105
+ )
106
+ expect(page.widget_data(1, timespan: 1)[:series]).to eq(
104
107
  {
105
108
  titles: [a_sensor.annotation, b_sensor.annotation],
106
109
  rows: [],
@@ -109,6 +112,7 @@ describe PulseMeter::Visualize::Page do
109
112
  {color: b_color}
110
113
  ]
111
114
  }
115
+ )
112
116
 
113
117
  end
114
118
 
@@ -117,16 +121,16 @@ describe PulseMeter::Visualize::Page do
117
121
  end
118
122
 
119
123
  describe "#widget_datas" do
120
- it "should generate correct ids for all widgets" do
124
+ it "generates correct ids for all widgets" do
121
125
  Timecop.freeze(interval_start + 2 * interval - 1) do
122
- page.widget_datas.map{|h| h[:id]}.should == [1,2]
126
+ expect(page.widget_datas.map{|h| h[:id]}).to eq([1,2])
123
127
  end
124
128
  end
125
129
 
126
- it "should generate correct series data of all widgets" do
130
+ it "generates correct series data of all widgets" do
127
131
  Timecop.freeze(interval_start + 2 * interval - 1) do
128
132
 
129
- page.widget_datas.map{|h| h[:series]}.should == [
133
+ expect(page.widget_datas.map{|h| h[:series]}).to eq([
130
134
  {
131
135
  data: [
132
136
  [a_sensor.annotation, 12],
@@ -145,7 +149,7 @@ describe PulseMeter::Visualize::Page do
145
149
  {color: b_color}
146
150
  ]
147
151
  }
148
- ]
152
+ ])
149
153
  end
150
154
 
151
155
  end
@@ -15,40 +15,40 @@ describe PulseMeter::Visualize::Sensor do
15
15
 
16
16
  describe '#last_value' do
17
17
  context "when sensor does not exist" do
18
- it "should raise RestoreError" do
18
+ it "raises RestoreError" do
19
19
  expect{ bad_sensor.last_value(Time.now) }.to raise_exception(PulseMeter::RestoreError)
20
20
  end
21
21
  end
22
22
 
23
23
 
24
24
  context "when sensor has no data" do
25
- it "should return nil" do
26
- sensor.last_value(Time.now).should be_nil
25
+ it "returns nil" do
26
+ expect(sensor.last_value(Time.now)).to be_nil
27
27
  end
28
28
  end
29
29
 
30
30
  context "when sensor has data" do
31
31
  context "when need_incomplete arg is true" do
32
- it "should return last value" do
32
+ it "returns last value" do
33
33
  Timecop.freeze(interval_start) do
34
34
  real_sensor.event(101)
35
35
  end
36
36
  Timecop.freeze(interval_start+1) do
37
- sensor.last_value(Time.now, true).should == 101
37
+ expect(sensor.last_value(Time.now, true)).to eq(101)
38
38
  end
39
39
  end
40
40
  end
41
41
 
42
42
  context "when need_incomplete arg is false" do
43
- it "should return last complete value" do
43
+ it "returns last complete value" do
44
44
  Timecop.freeze(interval_start) do
45
45
  real_sensor.event(101)
46
46
  end
47
47
  Timecop.freeze(interval_start + 1) do
48
- sensor.last_value(Time.now).should be_nil
48
+ expect(sensor.last_value(Time.now)).to be_nil
49
49
  end
50
50
  Timecop.freeze(interval_start + interval + 1) do
51
- sensor.last_value(Time.now).should == 101
51
+ expect(sensor.last_value(Time.now)).to eq(101)
52
52
  end
53
53
  end
54
54
  end
@@ -59,20 +59,20 @@ describe PulseMeter::Visualize::Sensor do
59
59
  describe "#last_point_data" do
60
60
 
61
61
  context "when sensor does not exist" do
62
- it "should raise RestoreError" do
62
+ it "raises RestoreError" do
63
63
  expect{ bad_sensor.last_point_data(Time.now) }.to raise_exception(PulseMeter::RestoreError)
64
64
  end
65
65
  end
66
66
 
67
- it "should return last value with annotation (and color)" do
67
+ it "returns last value with annotation (and color)" do
68
68
  Timecop.freeze(interval_start) do
69
69
  real_sensor.event(101)
70
70
  end
71
71
  Timecop.freeze(interval_start + 1) do
72
- sensor.last_point_data(Time.now, true).should == [{name: annotation, y: 101}]
73
- sensor.last_point_data(Time.now).should == [{name: annotation, y: nil}]
74
- sensor_with_color.last_point_data(Time.now, true).should == [{name: annotation, y: 101, color: color}]
75
- sensor_with_color.last_point_data(Time.now).should == [{name: annotation, y: nil, color: color}]
72
+ expect(sensor.last_point_data(Time.now, true)).to eq([{name: annotation, y: 101}])
73
+ expect(sensor.last_point_data(Time.now)).to eq([{name: annotation, y: nil}])
74
+ expect(sensor_with_color.last_point_data(Time.now, true)).to eq([{name: annotation, y: 101, color: color}])
75
+ expect(sensor_with_color.last_point_data(Time.now)).to eq([{name: annotation, y: nil, color: color}])
76
76
  end
77
77
  end
78
78
  end
@@ -81,11 +81,11 @@ describe PulseMeter::Visualize::Sensor do
81
81
  subject{ checked_sensor.valid? }
82
82
  context "when sensor exists" do
83
83
  let(:checked_sensor){ sensor }
84
- it{ should == true }
84
+ it{ is_expected.to eq(true) }
85
85
  end
86
86
  context "when sensor does not exist" do
87
87
  let(:checked_sensor){ bad_sensor }
88
- it{ should == false }
88
+ it{ is_expected.to eq(false) }
89
89
  end
90
90
  end
91
91
 
@@ -100,30 +100,30 @@ describe PulseMeter::Visualize::Sensor do
100
100
  end
101
101
 
102
102
  context "when sensor does not exist" do
103
- it "should raise RestoreError" do
103
+ it "raises RestoreError" do
104
104
  expect{ bad_sensor.timeline_data(Time.now - interval, Time.now) }.to raise_exception(PulseMeter::RestoreError)
105
105
  end
106
106
  end
107
107
 
108
108
 
109
109
  describe "returned value" do
110
- it "should contain sensor annotation" do
110
+ it "contains sensor annotation" do
111
111
  Timecop.freeze(interval_start + interval + 1) do
112
- sensor.timeline_data(Time.now - interval, Time.now).first[:name].should == annotation
112
+ expect(sensor.timeline_data(Time.now - interval, Time.now).first[:name]).to eq(annotation)
113
113
  end
114
114
  end
115
- it "should contain sensor color" do
115
+ it "contains sensor color" do
116
116
  Timecop.freeze(interval_start + interval + 1) do
117
- sensor_with_color.timeline_data(Time.now - interval, Time.now).first[:color].should == color
117
+ expect(sensor_with_color.timeline_data(Time.now - interval, Time.now).first[:color]).to eq(color)
118
118
  end
119
119
  end
120
120
 
121
- it "should contain [interval_start, value] pairs for each interval" do
121
+ it "contains [interval_start, value] pairs for each interval" do
122
122
  Timecop.freeze(interval_start + interval + 1) do
123
123
  data = sensor.timeline_data(Time.now - interval * 2, Time.now)
124
- data.first[:data].should == [{x: interval_start.to_i * 1000, y: 101}]
124
+ expect(data.first[:data]).to eq([{x: interval_start.to_i * 1000, y: 101}])
125
125
  data = sensor.timeline_data(Time.now - interval * 2, Time.now, true)
126
- data.first[:data].should == [{x: interval_start.to_i * 1000, y: 101}, {x: (interval_start + interval).to_i * 1000, y: 55}]
126
+ expect(data.first[:data]).to eq([{x: interval_start.to_i * 1000, y: 101}, {x: (interval_start + interval).to_i * 1000, y: 55}])
127
127
  end
128
128
  end
129
129
  end
@@ -20,23 +20,23 @@ describe PulseMeter::Visualize::SeriesExtractor do
20
20
 
21
21
  let(:extractor) {PulseMeter::Visualize.extractor(simple_sensor)}
22
22
 
23
- it "should be created for simple sensors" do
24
- extractor.should be_kind_of(PulseMeter::Visualize::SeriesExtractor::Simple)
23
+ it "is created for simple sensors" do
24
+ expect(extractor).to be_kind_of(PulseMeter::Visualize::SeriesExtractor::Simple)
25
25
  end
26
26
 
27
- it "should create point data correctly" do
28
- extractor.point_data(123).should == [{y: 123, name: 'simple sensor'}]
27
+ it "creates point data correctly" do
28
+ expect(extractor.point_data(123)).to eq([{y: 123, name: 'simple sensor'}])
29
29
  end
30
30
 
31
- it "should create timeline data correctly" do
31
+ it "creates timeline data correctly" do
32
32
  tl_data = [
33
33
  PulseMeter::SensorData.new(Time.at(1), 11),
34
34
  PulseMeter::SensorData.new(Time.at(2), "22")
35
35
  ]
36
- extractor.series_data(tl_data).should == [{
36
+ expect(extractor.series_data(tl_data)).to eq([{
37
37
  name: 'simple sensor',
38
38
  data: [{x: 1000, y: 11}, {x: 2000, y: 22}]
39
- }]
39
+ }])
40
40
  end
41
41
 
42
42
  end
@@ -44,23 +44,23 @@ describe PulseMeter::Visualize::SeriesExtractor do
44
44
  describe "hash extractor" do
45
45
  let(:extractor) {PulseMeter::Visualize.extractor(hashed_sensor)}
46
46
 
47
- it "should be created for hash sensors" do
48
- extractor.should be_kind_of(PulseMeter::Visualize::SeriesExtractor::Hashed)
47
+ it "is created for hash sensors" do
48
+ expect(extractor).to be_kind_of(PulseMeter::Visualize::SeriesExtractor::Hashed)
49
49
  end
50
50
 
51
- it "should create point data correctly" do
52
- extractor.point_data('{"x": 123, "y": 321}').should == [
51
+ it "creates point data correctly" do
52
+ expect(extractor.point_data('{"x": 123, "y": 321}')).to eq([
53
53
  {y: 123, name: 'hashed sensor: x'},
54
54
  {y: 321, name: 'hashed sensor: y'}
55
- ]
55
+ ])
56
56
  end
57
57
 
58
- it "should create timeline data correctly" do
58
+ it "creates timeline data correctly" do
59
59
  tl_data = [
60
60
  PulseMeter::SensorData.new(Time.at(1), {"a" => 5, "b" => 6}),
61
61
  PulseMeter::SensorData.new(Time.at(2), '{"c": 7, "b": 6}')
62
62
  ]
63
- extractor.series_data(tl_data).should == [
63
+ expect(extractor.series_data(tl_data)).to eq([
64
64
  {
65
65
  name: 'hashed sensor: a',
66
66
  data: [{x: 1000, y: 5}, {x: 2000, y: nil}]
@@ -73,7 +73,7 @@ describe PulseMeter::Visualize::SeriesExtractor do
73
73
  name: 'hashed sensor: c',
74
74
  data: [{x: 1000, y: nil}, {x: 2000, y: 7}]
75
75
  }
76
- ]
76
+ ])
77
77
  end
78
78
  end
79
79
 
@@ -26,13 +26,13 @@ describe PulseMeter::Visualize::Widgets::Gauge do
26
26
  end
27
27
 
28
28
  describe "#data" do
29
- it "should contain type, title, redraw_interval, width, gchart_options attriutes" do
29
+ it "contains type, title, redraw_interval, width, gchart_options attriutes" do
30
30
  wdata = widget.data
31
- wdata[:type].should == 'gauge'
32
- wdata[:title].should == widget_name
33
- wdata[:redraw_interval].should == redraw_interval
34
- wdata[:width].should == width
35
- wdata[:gchart_options].should == {a: 1}
31
+ expect(wdata[:type]).to eq('gauge')
32
+ expect(wdata[:title]).to eq(widget_name)
33
+ expect(wdata[:redraw_interval]).to eq(redraw_interval)
34
+ expect(wdata[:width]).to eq(width)
35
+ expect(wdata[:gchart_options]).to eq({a: 1})
36
36
  end
37
37
 
38
38
  describe "series attribute" do
@@ -43,14 +43,14 @@ describe PulseMeter::Visualize::Widgets::Gauge do
43
43
  c_sensor.event(:b => 55)
44
44
  end
45
45
 
46
- it "should contain valid gauge slices" do
46
+ it "contains valid gauge slices" do
47
47
 
48
- widget.data[:series].sort.should == [
48
+ expect(widget.data[:series].sort).to eq([
49
49
  ['A', 12],
50
50
  ['B', 33],
51
51
  ["C: a", 44],
52
52
  ["C: b", 55]
53
- ].sort
53
+ ].sort)
54
54
 
55
55
  end
56
56
 
@@ -26,13 +26,13 @@ describe PulseMeter::Visualize::Widgets::Pie do
26
26
  end
27
27
 
28
28
  describe "#data" do
29
- it "should contain type, title, redraw_interval, width, gchart_options attriutes" do
29
+ it "contains type, title, redraw_interval, width, gchart_options attriutes" do
30
30
  wdata = widget.data
31
- wdata[:type].should == 'pie'
32
- wdata[:title].should == widget_name
33
- wdata[:redraw_interval].should == redraw_interval
34
- wdata[:width].should == width
35
- wdata[:gchart_options].should == {a: 1}
31
+ expect(wdata[:type]).to eq('pie')
32
+ expect(wdata[:title]).to eq(widget_name)
33
+ expect(wdata[:redraw_interval]).to eq(redraw_interval)
34
+ expect(wdata[:width]).to eq(width)
35
+ expect(wdata[:gchart_options]).to eq({a: 1})
36
36
  end
37
37
 
38
38
  describe "series attribute" do
@@ -47,10 +47,10 @@ describe PulseMeter::Visualize::Widgets::Pie do
47
47
  @current_time = interval_start + 2 * interval - 1
48
48
  end
49
49
 
50
- it "should contain valid pie slices" do
50
+ it "contains valid pie slices" do
51
51
 
52
52
  Timecop.freeze(@current_time) do
53
- widget.data[:series].should ==
53
+ expect(widget.data[:series]).to eq(
54
54
  {
55
55
  data: [
56
56
  [a_sensor.annotation, 12],
@@ -61,6 +61,7 @@ describe PulseMeter::Visualize::Widgets::Pie do
61
61
  {color: b_color}
62
62
  ]
63
63
  }
64
+ )
64
65
  end
65
66
 
66
67
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe PulseMeter::Visualizer do
4
4
  describe "::draw" do
5
- it "should generate correct layout with passed block" do
5
+ it "generates correct layout with passed block" do
6
6
  layout = described_class.draw do |l|
7
7
 
8
8
  l.title "My Gauges"
@@ -26,7 +26,7 @@ describe PulseMeter::Visualizer do
26
26
  p.line :rph_total, sensor: :rph_total
27
27
  p.line :rph_main_page, sensor: :rph_main_page
28
28
  p.line :request_time_p95_hour
29
-
29
+
30
30
  p.pie :success_vs_fail_total_hourly do |w|
31
31
  w.sensor :success_total_hourly
32
32
  w.sensor :fail_total_hourly
@@ -35,7 +35,7 @@ describe PulseMeter::Visualizer do
35
35
  end
36
36
 
37
37
  end
38
- layout.should be_kind_of(PulseMeter::Visualize::Layout)
38
+ expect(layout).to be_kind_of(PulseMeter::Visualize::Layout)
39
39
  end
40
40
  end
41
41
  end
@@ -8,33 +8,33 @@ shared_examples_for "dsl widget" do
8
8
  let(:w){ described_class.new(widget_name) }
9
9
 
10
10
  describe '.new' do
11
- it "should set default value for width papram" do
11
+ it "sets default value for width papram" do
12
12
  wid = w.to_data
13
- wid.width.should == PulseMeter::Visualize::DSL::Widget::MAX_WIDTH
13
+ expect(wid.width).to eq(PulseMeter::Visualize::DSL::Widget::MAX_WIDTH)
14
14
  end
15
15
 
16
- it "should set title param from .new argument" do
16
+ it "sets title param from .new argument" do
17
17
  wid = w.to_data
18
- wid.title.should == widget_name
18
+ expect(wid.title).to eq(widget_name)
19
19
  end
20
20
  end
21
21
 
22
22
  describe "#process_args" do
23
- it "should set sensor by :sensor param" do
23
+ it "sets sensor by :sensor param" do
24
24
  w.process_args :sensor => :some_sensor
25
25
  sensors = w.to_data.sensors
26
- sensors.size.should == 1
27
- sensors.first.name.to_s.should == 'some_sensor'
26
+ expect(sensors.size).to eq(1)
27
+ expect(sensors.first.name.to_s).to eq('some_sensor')
28
28
  end
29
29
 
30
- it "should set title by :title param" do
30
+ it "sets title by :title param" do
31
31
  w.process_args :title => 'Title XXX'
32
- w.to_data.title.should == 'Title XXX'
32
+ expect(w.to_data.title).to eq('Title XXX')
33
33
  end
34
34
 
35
- it "should set width by :width param" do
35
+ it "sets width by :width param" do
36
36
  w.process_args :width => 5
37
- w.to_data.width.should == 5
37
+ expect(w.to_data.width).to eq(5)
38
38
  end
39
39
 
40
40
  end
@@ -44,66 +44,66 @@ shared_examples_for "dsl widget" do
44
44
  let!(:s2){ PulseMeter::Sensor::Timelined::Max.new('s2', :ttl => 1000, :interval => interval) }
45
45
 
46
46
 
47
- it "should add sensor" do
47
+ it "adds sensor" do
48
48
  w.sensor :s1
49
49
  w.sensor :s2
50
50
  sensors = w.to_data.sensors
51
- sensors.size.should == 2
52
- sensors.first.name.to_s.should == 's1'
53
- sensors.last.name.to_s.should == 's2'
51
+ expect(sensors.size).to eq(2)
52
+ expect(sensors.first.name.to_s).to eq('s1')
53
+ expect(sensors.last.name.to_s).to eq('s2')
54
54
  end
55
55
  end
56
56
 
57
57
  describe "#title" do
58
- it "should set title" do
58
+ it "sets title" do
59
59
  w.title 'Title XXX'
60
- w.to_data.title.should == 'Title XXX'
60
+ expect(w.to_data.title).to eq('Title XXX')
61
61
  w.title 'Title YYY'
62
- w.to_data.title.should == 'Title YYY'
62
+ expect(w.to_data.title).to eq('Title YYY')
63
63
  end
64
64
  end
65
65
 
66
66
  describe "#width" do
67
- it "should set width" do
67
+ it "sets width" do
68
68
  w.width 6
69
- w.to_data.width.should == 6
69
+ expect(w.to_data.width).to eq(6)
70
70
  end
71
71
 
72
- it "should raise exception if width is invalid" do
72
+ it "raises exception if width is invalid" do
73
73
  expect { w.width -1 }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetWidth)
74
74
  expect { w.width 13 }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetWidth)
75
75
  end
76
76
  end
77
77
 
78
78
  describe "#redraw_interval" do
79
- it "should set redraw_interval" do
79
+ it "sets redraw_interval" do
80
80
  w.redraw_interval 5
81
- w.to_data.redraw_interval.should == 5
81
+ expect(w.to_data.redraw_interval).to eq(5)
82
82
  end
83
- it "should raise exception if redraw_interval is negative" do
83
+ it "raises exception if redraw_interval is negative" do
84
84
  expect{ w.redraw_interval(-1) }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetRedrawInterval)
85
85
  end
86
86
 
87
87
  end
88
88
 
89
89
  describe "#to_data" do
90
- it "should convert dsl data to widget" do
91
- w.to_data.should be_kind_of(PulseMeter::Visualize::Widget)
90
+ it "converts dsl data to widget" do
91
+ expect(w.to_data).to be_kind_of(PulseMeter::Visualize::Widget)
92
92
  end
93
93
  end
94
94
 
95
95
  describe "#gchart_options" do
96
- it "should add options to gchart_options hash" do
96
+ it "adds options to gchart_options hash" do
97
97
  w.gchart_options a: 1
98
98
  w.gchart_options b: 2
99
- w.to_data.gchart_options.should == {a: 1, b: 2}
99
+ expect(w.to_data.gchart_options).to eq({a: 1, b: 2})
100
100
  end
101
101
  end
102
102
 
103
103
  describe "any anknown method" do
104
- it "should add options to gchart_options hash" do
104
+ it "adds options to gchart_options hash" do
105
105
  w.foobar 123
106
- w.to_data.gchart_options.should == {foobar: 123}
106
+ expect(w.to_data.gchart_options).to eq({foobar: 123})
107
107
  end
108
108
  end
109
109
  end