rrd-grapher 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/.gitignore +9 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +11 -0
  4. data/Guardfile +123 -0
  5. data/README.md +91 -0
  6. data/Rakefile +42 -0
  7. data/example_app/Gemfile +9 -0
  8. data/example_app/Guardfile +18 -0
  9. data/example_app/app.rb +38 -0
  10. data/example_app/assets/javascripts/available_rrds.coffee +13 -0
  11. data/example_app/assets/javascripts/collectd.coffee +48 -0
  12. data/example_app/config.ru +9 -0
  13. data/example_app/public/.gitignore +1 -0
  14. data/example_app/public/chosen/chosen-sprite.png +0 -0
  15. data/example_app/public/chosen/chosen.css +340 -0
  16. data/example_app/public/chosen/chosen.jquery.js +786 -0
  17. data/example_app/public/chosen/chosen.jquery.min.js +10 -0
  18. data/example_app/public/javascripts/available_rrds.js +16 -0
  19. data/example_app/public/javascripts/collectd.js +64 -0
  20. data/example_app/public/javascripts/jquery.timeago.js +148 -0
  21. data/example_app/public/stylesheets/Aristo/images/bg_fallback.png +0 -0
  22. data/example_app/public/stylesheets/Aristo/images/icon_sprite.png +0 -0
  23. data/example_app/public/stylesheets/Aristo/images/progress_bar.gif +0 -0
  24. data/example_app/public/stylesheets/Aristo/images/slider_handles.png +0 -0
  25. data/example_app/public/stylesheets/Aristo/images/ui-icons_222222_256x240.png +0 -0
  26. data/example_app/public/stylesheets/Aristo/images/ui-icons_454545_256x240.png +0 -0
  27. data/example_app/public/stylesheets/Aristo/theme.css +738 -0
  28. data/example_app/views/available_rrds.haml +26 -0
  29. data/example_app/views/collectd.haml +30 -0
  30. data/example_app/views/layout.haml +19 -0
  31. data/example_app/views/stylesheets/available_rrds.scss +7 -0
  32. data/example_notifier/Gemfile +2 -0
  33. data/example_notifier/notifier.rb +25 -0
  34. data/lib/rrd-grapher/assets/javascripts/app-dev.js +20 -0
  35. data/lib/rrd-grapher/assets/javascripts/app.js +20 -0
  36. data/lib/rrd-grapher/assets/javascripts/classes/format.coffee +35 -0
  37. data/lib/rrd-grapher/assets/javascripts/classes/graph.coffee +306 -0
  38. data/lib/rrd-grapher/assets/javascripts/classes/graph_definition.coffee +216 -0
  39. data/lib/rrd-grapher/assets/javascripts/classes/serie.coffee +13 -0
  40. data/lib/rrd-grapher/assets/javascripts/classes/size.coffee +5 -0
  41. data/lib/rrd-grapher/assets/javascripts/classes/static_line.coffee +44 -0
  42. data/lib/rrd-grapher/assets/javascripts/classes/time.coffee +17 -0
  43. data/lib/rrd-grapher/notifier/alarm_manager.rb +190 -0
  44. data/lib/rrd-grapher/notifier/alarm_trigger.rb +187 -0
  45. data/lib/rrd-grapher/notifier/alarms.rb +79 -0
  46. data/lib/rrd-grapher/notifier/collectdrb.rb +86 -0
  47. data/lib/rrd-grapher/notifier/data_struct.rb +46 -0
  48. data/lib/rrd-grapher/notifier/default_user_handler.rb +36 -0
  49. data/lib/rrd-grapher/notifier/parsers/bindata_parser.rb +144 -0
  50. data/lib/rrd-grapher/notifier/parsers/ruby_parser.rb +134 -0
  51. data/lib/rrd-grapher/notifier/structures.rb +80 -0
  52. data/lib/rrd-grapher/notifier.rb +87 -0
  53. data/lib/rrd-grapher/public/favicon.ico +0 -0
  54. data/lib/rrd-grapher/public/javascripts/app-dev.js +13709 -0
  55. data/lib/rrd-grapher/public/javascripts/app.js +4057 -0
  56. data/lib/rrd-grapher/public/javascripts/backbone/backbone.js +1155 -0
  57. data/lib/rrd-grapher/public/javascripts/backbone/backbone.min.js +32 -0
  58. data/lib/rrd-grapher/public/javascripts/backbone/underscore.js +841 -0
  59. data/lib/rrd-grapher/public/javascripts/backbone/underscore.min.js +27 -0
  60. data/lib/rrd-grapher/public/javascripts/classes/format.js +42 -0
  61. data/lib/rrd-grapher/public/javascripts/classes/graph.js +360 -0
  62. data/lib/rrd-grapher/public/javascripts/classes/graph_definition.js +298 -0
  63. data/lib/rrd-grapher/public/javascripts/classes/serie.js +32 -0
  64. data/lib/rrd-grapher/public/javascripts/classes/size.js +7 -0
  65. data/lib/rrd-grapher/public/javascripts/classes/static_line.js +48 -0
  66. data/lib/rrd-grapher/public/javascripts/classes/time.js +17 -0
  67. data/lib/rrd-grapher/public/javascripts/flot/.gitignore +4 -0
  68. data/lib/rrd-grapher/public/javascripts/flot/excanvas.min.js +1 -0
  69. data/lib/rrd-grapher/public/javascripts/flot/jquery.colorhelpers.min.js +1 -0
  70. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.crosshair.min.js +1 -0
  71. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.fillbetween.min.js +1 -0
  72. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.image.min.js +1 -0
  73. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.js +2604 -0
  74. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.navigate.min.js +1 -0
  75. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.pie.min.js +1 -0
  76. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.resize.min.js +1 -0
  77. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.selection.js +345 -0
  78. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.selection.min.js +1 -0
  79. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.stack.min.js +1 -0
  80. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.symbol.min.js +1 -0
  81. data/lib/rrd-grapher/public/javascripts/flot/jquery.flot.threshold.min.js +1 -0
  82. data/lib/rrd-grapher/public/javascripts/jquery/jquery-1.6.2.js +8981 -0
  83. data/lib/rrd-grapher/public/javascripts/jquery/jquery-1.6.2.min.js +18 -0
  84. data/lib/rrd-grapher/public/javascripts/jquery/jquery-ui-1.8.11.min.js +783 -0
  85. data/lib/rrd-grapher/public/javascripts/jquery/jquery.showtime.js +63 -0
  86. data/lib/rrd-grapher/public/javascripts/jquery/jquery.tpl.min.js +10 -0
  87. data/lib/rrd-grapher/resources.rb +14 -0
  88. data/lib/rrd-grapher/rrd.rb +238 -0
  89. data/lib/rrd-grapher/rrd_server.rb +78 -0
  90. data/lib/rrd-grapher/version.rb +4 -0
  91. data/lib/rrd-grapher/views/stylesheets/app.scss +111 -0
  92. data/lib/rrd-grapher.rb +12 -0
  93. data/rrd-grapher.gemspec +47 -0
  94. data/spec/common.rb +70 -0
  95. data/spec/data/myrouter.rrd +0 -0
  96. data/spec/data/subdata.rrd +0 -0
  97. data/spec/data/test.rrd +0 -0
  98. data/spec/factories.rb +23 -0
  99. data/spec/javascripts/helpers/jasmine-jquery-1.3.0.js +283 -0
  100. data/spec/javascripts/source/format_spec.coffee +18 -0
  101. data/spec/javascripts/source/graph_def_spec.coffee +27 -0
  102. data/spec/javascripts/source/graph_spec.coffee +63 -0
  103. data/spec/javascripts/source/serie_spec.coffee +28 -0
  104. data/spec/javascripts/source/static_line_spec.coffee +13 -0
  105. data/spec/javascripts/source/time_spec.coffee +26 -0
  106. data/spec/javascripts/support/jasmine.yml +78 -0
  107. data/spec/javascripts/support/jasmine_config.rb +23 -0
  108. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  109. data/spec/unit/alarm_manager_spec.rb +252 -0
  110. data/spec/unit/alarm_trigger_spec.rb +26 -0
  111. data/spec/unit/data_struct_spec.rb +55 -0
  112. data/spec/unit/notifier_spec.rb +45 -0
  113. data/spec/unit/parsers/bindata_parser_spec.rb +184 -0
  114. data/spec/unit/parsers/ruby_parser_spec.rb +184 -0
  115. data/spec/unit/rrd_spec.rb +50 -0
  116. data/spec/unit/structures_spec.rb +28 -0
  117. data/tests/4series.rrd +0 -0
  118. data/tests/analyze_rrd.rb +62 -0
  119. data/tests/exact.rrd +0 -0
  120. data/tests/exact2.rrd +0 -0
  121. data/tests/filler.rb +46 -0
  122. metadata +414 -0
@@ -0,0 +1,283 @@
1
+ var readFixtures = function() {
2
+ return jasmine.getFixtures().proxyCallTo_('read', arguments);
3
+ };
4
+
5
+ var preloadFixtures = function() {
6
+ jasmine.getFixtures().proxyCallTo_('preload', arguments);
7
+ };
8
+
9
+ var loadFixtures = function() {
10
+ jasmine.getFixtures().proxyCallTo_('load', arguments);
11
+ };
12
+
13
+ var setFixtures = function(html) {
14
+ jasmine.getFixtures().set(html);
15
+ };
16
+
17
+ var sandbox = function(attributes) {
18
+ return jasmine.getFixtures().sandbox(attributes);
19
+ };
20
+
21
+ var spyOnEvent = function(selector, eventName) {
22
+ jasmine.JQuery.events.spyOn(selector, eventName);
23
+ }
24
+
25
+ jasmine.getFixtures = function() {
26
+ return jasmine.currentFixtures_ = jasmine.currentFixtures_ || new jasmine.Fixtures();
27
+ };
28
+
29
+ jasmine.Fixtures = function() {
30
+ this.containerId = 'jasmine-fixtures';
31
+ this.fixturesCache_ = {};
32
+ this.fixturesPath = 'spec/javascripts/fixtures';
33
+ };
34
+
35
+ jasmine.Fixtures.prototype.set = function(html) {
36
+ this.cleanUp();
37
+ this.createContainer_(html);
38
+ };
39
+
40
+ jasmine.Fixtures.prototype.preload = function() {
41
+ this.read.apply(this, arguments);
42
+ };
43
+
44
+ jasmine.Fixtures.prototype.load = function() {
45
+ this.cleanUp();
46
+ this.createContainer_(this.read.apply(this, arguments));
47
+ };
48
+
49
+ jasmine.Fixtures.prototype.read = function() {
50
+ var htmlChunks = [];
51
+
52
+ var fixtureUrls = arguments;
53
+ for(var urlCount = fixtureUrls.length, urlIndex = 0; urlIndex < urlCount; urlIndex++) {
54
+ htmlChunks.push(this.getFixtureHtml_(fixtureUrls[urlIndex]));
55
+ }
56
+
57
+ return htmlChunks.join('');
58
+ };
59
+
60
+ jasmine.Fixtures.prototype.clearCache = function() {
61
+ this.fixturesCache_ = {};
62
+ };
63
+
64
+ jasmine.Fixtures.prototype.cleanUp = function() {
65
+ jQuery('#' + this.containerId).remove();
66
+ };
67
+
68
+ jasmine.Fixtures.prototype.sandbox = function(attributes) {
69
+ var attributesToSet = attributes || {};
70
+ return jQuery('<div id="sandbox" />').attr(attributesToSet);
71
+ };
72
+
73
+ jasmine.Fixtures.prototype.createContainer_ = function(html) {
74
+ var container = jQuery('<div id="' + this.containerId + '" />');
75
+ container.html(html);
76
+ jQuery('body').append(container);
77
+ };
78
+
79
+ jasmine.Fixtures.prototype.getFixtureHtml_ = function(url) {
80
+ if (typeof this.fixturesCache_[url] == 'undefined') {
81
+ this.loadFixtureIntoCache_(url);
82
+ }
83
+ return this.fixturesCache_[url];
84
+ };
85
+
86
+ jasmine.Fixtures.prototype.loadFixtureIntoCache_ = function(relativeUrl) {
87
+ var self = this;
88
+ var url = this.fixturesPath.match('/$') ? this.fixturesPath + relativeUrl : this.fixturesPath + '/' + relativeUrl;
89
+ jQuery.ajax({
90
+ async: false, // must be synchronous to guarantee that no tests are run before fixture is loaded
91
+ cache: false,
92
+ dataType: 'html',
93
+ url: url,
94
+ success: function(data) {
95
+ self.fixturesCache_[relativeUrl] = data;
96
+ },
97
+ error: function(jqXHR, status, errorThrown) {
98
+ throw Error('Fixture could not be loaded: ' + url + ' (status: ' + status + ', message: ' + errorThrown.message + ')');
99
+ }
100
+ });
101
+ };
102
+
103
+ jasmine.Fixtures.prototype.proxyCallTo_ = function(methodName, passedArguments) {
104
+ return this[methodName].apply(this, passedArguments);
105
+ };
106
+
107
+
108
+ jasmine.JQuery = function() {};
109
+
110
+ jasmine.JQuery.browserTagCaseIndependentHtml = function(html) {
111
+ return jQuery('<div/>').append(html).html();
112
+ };
113
+
114
+ jasmine.JQuery.elementToString = function(element) {
115
+ return jQuery('<div />').append(element.clone()).html();
116
+ };
117
+
118
+ jasmine.JQuery.matchersClass = {};
119
+
120
+ (function(namespace) {
121
+ var data = {
122
+ spiedEvents: {},
123
+ handlers: []
124
+ };
125
+
126
+ namespace.events = {
127
+ spyOn: function(selector, eventName) {
128
+ var handler = function(e) {
129
+ data.spiedEvents[[selector, eventName]] = e;
130
+ };
131
+ jQuery(selector).bind(eventName, handler);
132
+ data.handlers.push(handler);
133
+ },
134
+
135
+ wasTriggered: function(selector, eventName) {
136
+ return !!(data.spiedEvents[[selector, eventName]]);
137
+ },
138
+
139
+ cleanUp: function() {
140
+ data.spiedEvents = {};
141
+ data.handlers = [];
142
+ }
143
+ }
144
+ })(jasmine.JQuery);
145
+
146
+ (function(){
147
+ var jQueryMatchers = {
148
+ toHaveClass: function(className) {
149
+ return this.actual.hasClass(className);
150
+ },
151
+
152
+ toBeVisible: function() {
153
+ return this.actual.is(':visible');
154
+ },
155
+
156
+ toBeHidden: function() {
157
+ return this.actual.is(':hidden');
158
+ },
159
+
160
+ toBeSelected: function() {
161
+ return this.actual.is(':selected');
162
+ },
163
+
164
+ toBeChecked: function() {
165
+ return this.actual.is(':checked');
166
+ },
167
+
168
+ toBeEmpty: function() {
169
+ return this.actual.is(':empty');
170
+ },
171
+
172
+ toExist: function() {
173
+ return this.actual.size() > 0;
174
+ },
175
+
176
+ toHaveAttr: function(attributeName, expectedAttributeValue) {
177
+ return hasProperty(this.actual.attr(attributeName), expectedAttributeValue);
178
+ },
179
+
180
+ toHaveId: function(id) {
181
+ return this.actual.attr('id') == id;
182
+ },
183
+
184
+ toHaveHtml: function(html) {
185
+ return this.actual.html() == jasmine.JQuery.browserTagCaseIndependentHtml(html);
186
+ },
187
+
188
+ toHaveText: function(text) {
189
+ if (text && jQuery.isFunction(text.test)) {
190
+ return text.test(this.actual.text());
191
+ } else {
192
+ return this.actual.text() == text;
193
+ }
194
+ },
195
+
196
+ toHaveValue: function(value) {
197
+ return this.actual.val() == value;
198
+ },
199
+
200
+ toHaveData: function(key, expectedValue) {
201
+ return hasProperty(this.actual.data(key), expectedValue);
202
+ },
203
+
204
+ toBe: function(selector) {
205
+ return this.actual.is(selector);
206
+ },
207
+
208
+ toContain: function(selector) {
209
+ return this.actual.find(selector).size() > 0;
210
+ },
211
+
212
+ toBeDisabled: function(selector){
213
+ return this.actual.is(':disabled');
214
+ },
215
+
216
+ // tests the existence of a specific event binding
217
+ toHandle: function(eventName) {
218
+ var events = this.actual.data("events");
219
+ return events && events[eventName].length > 0;
220
+ },
221
+
222
+ // tests the existence of a specific event binding + handler
223
+ toHandleWith: function(eventName, eventHandler) {
224
+ var stack = this.actual.data("events")[eventName];
225
+ var i;
226
+ for (i = 0; i < stack.length; i++) {
227
+ if (stack[i].handler == eventHandler) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ }
233
+ };
234
+
235
+ var hasProperty = function(actualValue, expectedValue) {
236
+ if (expectedValue === undefined) {
237
+ return actualValue !== undefined;
238
+ }
239
+ return actualValue == expectedValue;
240
+ };
241
+
242
+ var bindMatcher = function(methodName) {
243
+ var builtInMatcher = jasmine.Matchers.prototype[methodName];
244
+
245
+ jasmine.JQuery.matchersClass[methodName] = function() {
246
+ if (this.actual instanceof jQuery) {
247
+ var result = jQueryMatchers[methodName].apply(this, arguments);
248
+ this.actual = jasmine.JQuery.elementToString(this.actual);
249
+ return result;
250
+ }
251
+
252
+ if (builtInMatcher) {
253
+ return builtInMatcher.apply(this, arguments);
254
+ }
255
+
256
+ return false;
257
+ };
258
+ };
259
+
260
+ for(var methodName in jQueryMatchers) {
261
+ bindMatcher(methodName);
262
+ }
263
+ })();
264
+
265
+ beforeEach(function() {
266
+ this.addMatchers(jasmine.JQuery.matchersClass);
267
+ this.addMatchers({
268
+ toHaveBeenTriggeredOn: function(selector) {
269
+ this.message = function() {
270
+ return [
271
+ "Expected event " + this.actual + " to have been triggered on" + selector,
272
+ "Expected event " + this.actual + " not to have been triggered on" + selector
273
+ ];
274
+ };
275
+ return jasmine.JQuery.events.wasTriggered(selector, this.actual);
276
+ }
277
+ })
278
+ });
279
+
280
+ afterEach(function() {
281
+ jasmine.getFixtures().cleanUp();
282
+ jasmine.JQuery.events.cleanUp();
283
+ });
@@ -0,0 +1,18 @@
1
+
2
+ describe "Format", ->
3
+ beforeEach ->
4
+ @f = Format
5
+
6
+ it "can format speed", ->
7
+ expect( @f.speed(2048) ).toEqual("2.00&nbsp;KB/s")
8
+ expect( @f.speed(2097152) ).toEqual("2.00&nbsp;MB/s")
9
+
10
+ it "can format size", ->
11
+ expect( @f.size(2048) ).toEqual("2.00&nbsp;KB")
12
+ expect( @f.size(2097152) ).toEqual("2.00&nbsp;MB")
13
+
14
+ it "can format time duration", ->
15
+ expect( @f.delay(100) ).toEqual("100.00&nbsp;ms")
16
+ expect( @f.delay(1000 * 2) ).toEqual("2.00&nbsp;s")
17
+ expect( @f.delay(1000 * 60 * 2) ).toEqual("2.00&nbsp;m")
18
+ expect( @f.delay(1000 * 60 * 60 * 2) ).toEqual("2.00&nbsp;h")
@@ -0,0 +1,27 @@
1
+
2
+ describe "NetworkGraph", ->
3
+ beforeEach ->
4
+ container = $('<div>')
5
+ @def = new NetworkGraph(container, "test.com", "en0")
6
+
7
+ it "should initialize correctly", ->
8
+ series = @def.graph.get("series")
9
+ expect(series.length).toEqual(2)
10
+ expect(series[0].rrd_path).toEqual("test.com/interface/if_octets-en0")
11
+ expect(series[1].rrd_path).toEqual("test.com/interface/if_octets-en0")
12
+
13
+ describe "GraphPage", ->
14
+ beforeEach ->
15
+ @container = $('<div>')
16
+ @page = new GraphPage(@container, "test.com")
17
+
18
+ it "can be created", ->
19
+ expect(@page.graphs).toEqual([])
20
+
21
+ it "can include graph definitions", ->
22
+ @page.addGraph("NetworkGraph", "en0")
23
+ expect(@page.graphs.length).toEqual(1)
24
+ expect(@page.graphs[0]).toEqual(jasmine.any(Object))
25
+ # check object "class", the should be a more straight forward way to do this...
26
+ expect(@page.graphs[0].constructor.prototype).toBe( (new NetworkGraph("a1")).constructor.prototype )
27
+
@@ -0,0 +1,63 @@
1
+
2
+ describe "Graph", ->
3
+ beforeEach ->
4
+ @container = $("<div>")
5
+ @graph = new Graph("Graph Title", @container, null, null)
6
+
7
+ it "should create required children", ->
8
+ expect(@container).toContain("div.graph_title")
9
+ expect(@container).toContain("div.graph_container")
10
+ expect(@container).toContain("div.legend")
11
+ expect(@container).toContain("div.graph")
12
+
13
+ it "should allow adding serie", ->
14
+ expect(@graph.get("series").length).toEqual(0)
15
+ create_spy = spyOn(window, "Serie")
16
+ @graph.addSerie("path/to/file.rrd", "my_ds", "legend_text", 1, null)
17
+ expect(@graph.get("series").length).toEqual(1)
18
+ # expect(create_spy).toHaveBeenCalledWith(["path/to/file.rrd", "my_ds", "legend_text", 1w, jasmine.any(Function)])
19
+
20
+ it "should allow addingd static lines", ->
21
+ expect(@graph.get("lines").length).toEqual(0)
22
+ @graph.addLine(13, "red")
23
+ expect(@graph.get("lines").length).toEqual(1)
24
+
25
+ it "should update its view when created", ->
26
+ update_spy = spyOn(@graph, "update_graph")
27
+ @graph.create()
28
+ expect(update_spy).toHaveBeenCalledWith(true)
29
+
30
+ it "should fetch new data when updating", ->
31
+ ajax_spies = spyOn(@graph, "multiple_get")
32
+ @graph.addSerie("path/to/file.rrd", "my_ds", "legend_text", 0, null)
33
+ @graph.update_graph(true)
34
+ expect(ajax_spies)
35
+
36
+ expect(ajax_spies.mostRecentCall.args.length).toEqual(2)
37
+ expect(ajax_spies.mostRecentCall.args[0][0]).toEqual([jasmine.any(String), jasmine.any(Object)])
38
+ # expect(ajax_spies.argsForCall[0][0][0]).toMatch("^\/rrd\/$")
39
+
40
+ it "should be able to fetch new data", ->
41
+ ajax_request = spyOn($, "getJSON")
42
+
43
+ cb = jasmine.createSpy()
44
+
45
+ s = new Object
46
+ s.set_data = jasmine.createSpy()
47
+ s.get_definition = jasmine.createSpy().andReturn("none")
48
+ # serie_set_data = spyOn(s, "set_data")
49
+
50
+ @graph.multiple_get([["/url1", s]], cb)
51
+
52
+ expect(ajax_request).toHaveBeenCalledWith("/url1", jasmine.any(Function))
53
+ ajax_request.mostRecentCall.args[1]([[0, 1], [1, 42]])
54
+ expect(s.set_data).toHaveBeenCalledWith([[0, 1], [1, 42]])
55
+
56
+ expect(cb).toHaveBeenCalledWith(["none"])
57
+
58
+ # it "should be able to play a Song", ->
59
+ # @player.play(@song)
60
+ # expect(@player.currentlyPlayingSong).toEqual(@song)
61
+ #
62
+ # # demonstrates use of custom matcher
63
+ # expect(@player).toBePlaying(@song)
@@ -0,0 +1,28 @@
1
+
2
+ describe "Serie", ->
3
+ beforeEach ->
4
+ @serie = new Serie("/rrd/path", "ds_name", "Serie Name")
5
+
6
+ it "should be enabled by default", ->
7
+ expect(@serie.enabled).toEqual(true)
8
+
9
+ it "should return its definition", ->
10
+ expected_def = {
11
+ data: [],
12
+ label: "Serie Name",
13
+ yaxis: 1,
14
+ color: 'black'
15
+ }
16
+ expect(@serie.get_definition()).toEqual(expected_def)
17
+
18
+ it "should allow toggling its enable state", ->
19
+ @serie.toggle_enabled()
20
+ expect(@serie.enabled).toEqual(false)
21
+ @serie.toggle_enabled()
22
+ expect(@serie.enabled).toEqual(true)
23
+
24
+ it "should allow directly setting its enable state", ->
25
+ @serie.set_enabled(false)
26
+ expect(@serie.enabled).toEqual(false)
27
+ @serie.set_enabled(true)
28
+ expect(@serie.enabled).toEqual(true)
@@ -0,0 +1,13 @@
1
+
2
+ describe "StaticLine", ->
3
+ beforeEach ->
4
+ @line = new StaticLine(13, "red")
5
+
6
+
7
+ it "should return its definition", ->
8
+ expected_def = {
9
+ data: [[jasmine.any(Number), 13], [jasmine.any(Number), 13]],
10
+ legend: "",
11
+ color: 'red'
12
+ }
13
+ expect(@line.get_definition(0, 1)).toEqual(expected_def)
@@ -0,0 +1,26 @@
1
+
2
+ describe "Time", ->
3
+ beforeEach ->
4
+ # fake a 10 seconds offset
5
+ Time.tz_offset = 10
6
+
7
+
8
+ it "can convert Time From UTC to local", ->
9
+ time = 100
10
+ utc_time = Time.utc_to_local(time)
11
+ expect(utc_time).toEqual( 110 )
12
+
13
+ it "can convert Time From local to UTC", ->
14
+ time = 100
15
+ utc_time = Time.local_to_utc(time)
16
+ expect(utc_time).toEqual( 90 )
17
+
18
+ it "can convert Client timestamp to Server timestamp", ->
19
+ client_time = 100 * 1000
20
+ server_time = Time.client_to_server(client_time)
21
+ expect(server_time).toEqual(90)
22
+
23
+ it "can convert Server timestamp to Client timestamp", ->
24
+ server_time = 90
25
+ client_time = Time.server_to_client(server_time)
26
+ expect(client_time).toEqual(100 * 1000)
@@ -0,0 +1,78 @@
1
+ # src_files
2
+ #
3
+ # Return an array of filepaths relative to src_dir to include before jasmine specs.
4
+ # Default: []
5
+ #
6
+ # EXAMPLE:
7
+ #
8
+ # src_files:
9
+ # - lib/source1.js
10
+ # - lib/source2.js
11
+ # - dist/**/*.js
12
+ #
13
+ src_files:
14
+ - lib/rrd-grapher/public/javascripts/jquery/jquery-1.6.2.js
15
+ - lib/rrd-grapher/public/javascripts/flot/jquery.flot.js
16
+ - lib/rrd-grapher/public/javascripts/backbone/underscore.js
17
+ - lib/rrd-grapher/public/javascripts/backbone/backbone.js
18
+ - lib/rrd-grapher/public/javascripts/app.js
19
+ - lib/rrd-grapher/public/javascripts/classes/**/*.js
20
+
21
+ # stylesheets
22
+ #
23
+ # Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
24
+ # Default: []
25
+ #
26
+ # EXAMPLE:
27
+ #
28
+ # stylesheets:
29
+ # - css/style.css
30
+ # - stylesheets/*.css
31
+ #
32
+ stylesheets:
33
+
34
+ # helpers
35
+ #
36
+ # Return an array of filepaths relative to spec_dir to include before jasmine specs.
37
+ # Default: ["helpers/**/*.js"]
38
+ #
39
+ # EXAMPLE:
40
+ #
41
+ # helpers:
42
+ # - helpers/**/*.js
43
+ #
44
+ helpers:
45
+
46
+ # spec_files
47
+ #
48
+ # Return an array of filepaths relative to spec_dir to include.
49
+ # Default: ["**/*[sS]pec.js"]
50
+ #
51
+ # EXAMPLE:
52
+ #
53
+ # spec_files:
54
+ # - **/*[sS]pec.js
55
+ #
56
+ spec_files:
57
+
58
+ # src_dir
59
+ #
60
+ # Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
61
+ # Default: project root
62
+ #
63
+ # EXAMPLE:
64
+ #
65
+ # src_dir: public
66
+ #
67
+ src_dir:
68
+
69
+ # spec_dir
70
+ #
71
+ # Spec directory path. Your spec_files must be returned relative to this path.
72
+ # Default: spec/javascripts
73
+ #
74
+ # EXAMPLE:
75
+ #
76
+ # spec_dir: spec/javascripts
77
+ #
78
+ spec_dir:
@@ -0,0 +1,23 @@
1
+ module Jasmine
2
+ class Config
3
+
4
+ # Add your overrides or custom config code here
5
+
6
+ end
7
+ end
8
+
9
+
10
+ # Note - this is necessary for rspec2, which has removed the backtrace
11
+ module Jasmine
12
+ class SpecBuilder
13
+ def declare_spec(parent, spec)
14
+ me = self
15
+ example_name = spec["name"]
16
+ @spec_ids << spec["id"]
17
+ backtrace = @example_locations[parent.description + " " + example_name]
18
+ parent.it example_name, {} do
19
+ me.report_spec(spec["id"])
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ $:.unshift(ENV['JASMINE_GEM_PATH']) if ENV['JASMINE_GEM_PATH'] # for gem testing purposes
2
+
3
+ require 'rubygems'
4
+ require 'jasmine'
5
+ jasmine_config_overrides = File.expand_path(File.join(File.dirname(__FILE__), 'jasmine_config.rb'))
6
+ require jasmine_config_overrides if File.exist?(jasmine_config_overrides)
7
+ if Jasmine::rspec2?
8
+ require 'rspec'
9
+ else
10
+ require 'spec'
11
+ end
12
+
13
+ jasmine_config = Jasmine::Config.new
14
+ spec_builder = Jasmine::SpecBuilder.new(jasmine_config)
15
+
16
+ should_stop = false
17
+
18
+ if Jasmine::rspec2?
19
+ RSpec.configuration.after(:suite) do
20
+ spec_builder.stop if should_stop
21
+ end
22
+ else
23
+ Spec::Runner.configure do |config|
24
+ config.after(:suite) do
25
+ spec_builder.stop if should_stop
26
+ end
27
+ end
28
+ end
29
+
30
+ spec_builder.start
31
+ should_stop = true
32
+ spec_builder.declare_suites