janitor_rails 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ module JanitorRails
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module JanitorRails
2
+ class TestController < JanitorRails::ApplicationController
3
+ layout false
4
+
5
+ def index
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Janitor test runner</title>
5
+ <%= javascript_include_tag 'janitor' %>
6
+ <%= javascript_include_tag 'test' %>
7
+ </head>
8
+ <body>
9
+ <div id="js_test_results"></div>
10
+
11
+ <script type="text/javascript">
12
+ new Janitor.BrowserRunner({ el: document.getElementById('js_test_results') }).run();
13
+ </script>
14
+ </body>
15
+ </html>
@@ -0,0 +1 @@
1
+ Rails.application.config.assets.paths << File.join(Rails.root, "test", "javascripts")
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ JanitorRails::Engine.routes.draw do
2
+ root to: "test#index"
3
+ end
4
+
5
+ Rails.application.routes.draw do
6
+ mount JanitorRails::Engine => "/janitor"
7
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'janitor_rails'
@@ -0,0 +1,5 @@
1
+ module JanitorRails
2
+ class Engine < Rails::Engine
3
+ isolate_namespace JanitorRails
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "janitor_rails/engine" if defined? Rails
@@ -0,0 +1,515 @@
1
+ window.Janitor = {};
2
+ window.Janitor.Stitch = {};
3
+ (function() {
4
+
5
+ (function(/*! Stitch !*/) {
6
+ if (!this.require) {
7
+ var modules = {}, cache = {}, require = function(name, root) {
8
+ var module = cache[name], path = expand(root, name), fn;
9
+ if (module) {
10
+ return module;
11
+ } else if (fn = modules[path] || modules[path = expand(path, './index')]) {
12
+ module = {id: name, exports: {}};
13
+ try {
14
+ cache[name] = module.exports;
15
+ fn(module.exports, function(name) {
16
+ return require(name, dirname(path));
17
+ }, module);
18
+ return cache[name] = module.exports;
19
+ } catch (err) {
20
+ delete cache[name];
21
+ throw err;
22
+ }
23
+ } else {
24
+ throw 'module \'' + name + '\' not found';
25
+ }
26
+ }, expand = function(root, name) {
27
+ var results = [], parts, part;
28
+ if (/^\.\.?(\/|$)/.test(name)) {
29
+ parts = [root, name].join('/').split('/');
30
+ } else {
31
+ parts = name.split('/');
32
+ }
33
+ for (var i = 0, length = parts.length; i < length; i++) {
34
+ part = parts[i];
35
+ if (part == '..') {
36
+ results.pop();
37
+ } else if (part != '.' && part != '') {
38
+ results.push(part);
39
+ }
40
+ }
41
+ return results.join('/');
42
+ }, dirname = function(path) {
43
+ return path.split('/').slice(0, -1).join('/');
44
+ };
45
+ this.require = function(name) {
46
+ return require(name, '');
47
+ }
48
+ this.require.define = function(bundle) {
49
+ for (var key in bundle)
50
+ modules[key] = bundle[key];
51
+ };
52
+ }
53
+ return this.require.define;
54
+ }).call(this)({"assertions": function(exports, require, module) {
55
+ module.exports = {
56
+ assertEqual: function(val1, val2) {
57
+ return this.store_assert('equal', val1 === val2, {
58
+ val1: val1,
59
+ val2: val2
60
+ });
61
+ },
62
+ assert: function(exp) {
63
+ return this.store_assert('true', exp, {
64
+ exp: exp
65
+ });
66
+ },
67
+ assertThrows: function(callback, check) {
68
+ var caught, error, success;
69
+ caught = false;
70
+ error = null;
71
+ try {
72
+ callback();
73
+ } catch (thrown_error) {
74
+ caught = true;
75
+ error = thrown_error;
76
+ }
77
+ success = caught && (!check || check(error));
78
+ return this.store_assert('throw', success, {
79
+ callback: callback,
80
+ error: error
81
+ });
82
+ },
83
+ refuteThrows: function(callback) {
84
+ var caught, error, success;
85
+ caught = false;
86
+ error = null;
87
+ try {
88
+ callback();
89
+ } catch (thrown_error) {
90
+ caught = true;
91
+ error = thrown_error;
92
+ }
93
+ success = !caught;
94
+ return this.store_assert('refute_throw', success, {
95
+ callback: callback,
96
+ error: error
97
+ });
98
+ },
99
+ assertContains: function(container, value) {
100
+ var result;
101
+ result = container.indexOf(value) !== -1;
102
+ return this.store_assert('contains', result, {
103
+ container: container,
104
+ value: value
105
+ });
106
+ }
107
+ };
108
+ }, "browser_presenter": function(exports, require, module) {(function() {
109
+ var Presenter;
110
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
111
+
112
+ Presenter = require('./presenter');
113
+
114
+ module.exports = (function() {
115
+
116
+ __extends(_Class, Presenter);
117
+
118
+ function _Class() {
119
+ _Class.__super__.constructor.apply(this, arguments);
120
+ }
121
+
122
+ _Class.prototype.outputFailedAssert = function(failed_assert) {
123
+ var el, text;
124
+ text = this.failedAssertDescription(failed_assert);
125
+ el = document.createElement('div');
126
+ el.innerHTML = text;
127
+ el.style.color = 'red';
128
+ return this.options.el.appendChild(el);
129
+ };
130
+
131
+ _Class.prototype.complete = function() {
132
+ var el;
133
+ el = document.createElement('div');
134
+ el.innerHTML = this.summaryMessage();
135
+ return this.options.el.appendChild(el);
136
+ };
137
+
138
+ return _Class;
139
+
140
+ })();
141
+
142
+ }).call(this);
143
+ }, "browser_runner": function(exports, require, module) {(function() {
144
+ var BrowserPresenter, Runner;
145
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
146
+
147
+ Runner = require('runner');
148
+
149
+ BrowserPresenter = require('browser_presenter');
150
+
151
+ module.exports = (function() {
152
+
153
+ __extends(_Class, Runner);
154
+
155
+ function _Class() {
156
+ _Class.__super__.constructor.apply(this, arguments);
157
+ }
158
+
159
+ _Class.prototype.presenter_class = BrowserPresenter;
160
+
161
+ _Class.prototype.tests = function() {
162
+ var key, _i, _len, _ref, _results;
163
+ _ref = Object.keys(window);
164
+ _results = [];
165
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
166
+ key = _ref[_i];
167
+ if (key.substr(-4) === 'Test') _results.push(window[key]);
168
+ }
169
+ return _results;
170
+ };
171
+
172
+ return _Class;
173
+
174
+ })();
175
+
176
+ }).call(this);
177
+ }, "console_presenter": function(exports, require, module) {(function() {
178
+ var Presenter;
179
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
180
+
181
+ Presenter = require('./presenter');
182
+
183
+ module.exports = (function() {
184
+
185
+ __extends(_Class, Presenter);
186
+
187
+ function _Class() {
188
+ _Class.__super__.constructor.apply(this, arguments);
189
+ }
190
+
191
+ _Class.prototype.outputFailedAssert = function(failed_assert) {
192
+ return console.log(this.failedAssertDescription(failed_assert));
193
+ };
194
+
195
+ _Class.prototype.complete = function() {
196
+ return console.log(this.summaryMessage());
197
+ };
198
+
199
+ return _Class;
200
+
201
+ })();
202
+
203
+ }).call(this);
204
+ }, "event_emitter": function(exports, require, module) {
205
+ module.exports = {
206
+ bind: function(event, callback) {
207
+ var _base;
208
+ this._callbacks || (this._callbacks = {});
209
+ (_base = this._callbacks)[event] || (_base[event] = []);
210
+ return this._callbacks[event].push(callback);
211
+ },
212
+ trigger: function(event, message) {
213
+ var callback, list, _i, _len, _results;
214
+ if (!(this._callbacks && (list = this._callbacks[event]))) return;
215
+ _results = [];
216
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
217
+ callback = list[_i];
218
+ _results.push(callback(message));
219
+ }
220
+ return _results;
221
+ }
222
+ };
223
+ }, "failed_assert_message_resolver": function(exports, require, module) {
224
+ module.exports = (function() {
225
+
226
+ function _Class(failed_assert) {
227
+ this.type = failed_assert.type;
228
+ this.options = failed_assert.options;
229
+ }
230
+
231
+ _Class.prototype.message = function() {
232
+ if (this[this.type]) {
233
+ return this[this.type]();
234
+ } else {
235
+ return "Unknown assert fail: " + this.type;
236
+ }
237
+ };
238
+
239
+ _Class.prototype.equal = function() {
240
+ return "" + this.options.val1 + " does not equal " + this.options.val2;
241
+ };
242
+
243
+ _Class.prototype["true"] = function() {
244
+ return "" + this.options.exp + " is not true";
245
+ };
246
+
247
+ return _Class;
248
+
249
+ })();
250
+ }, "main": function(exports, require, module) {
251
+ module.exports = {
252
+ TestCase: require('./test_case'),
253
+ NodeRunner: require('./node_runner')
254
+ };
255
+ }, "node_runner": function(exports, require, module) {(function() {
256
+ var ConsolePresenter, Glob, Runner;
257
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
258
+
259
+ ConsolePresenter = require('./console_presenter');
260
+
261
+ Runner = require('./runner');
262
+
263
+ Glob = require('glob');
264
+
265
+ module.exports = (function() {
266
+
267
+ __extends(_Class, Runner);
268
+
269
+ function _Class() {
270
+ _Class.__super__.constructor.apply(this, arguments);
271
+ }
272
+
273
+ _Class.prototype.presenter_class = ConsolePresenter;
274
+
275
+ _Class.prototype.tests = function() {
276
+ var file, _i, _len, _ref, _results;
277
+ _ref = this.files();
278
+ _results = [];
279
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
280
+ file = _ref[_i];
281
+ _results.push(require(file));
282
+ }
283
+ return _results;
284
+ };
285
+
286
+ _Class.prototype.files = function() {
287
+ return Glob.globSync("" + this.options.dir + "/**_test.coffee");
288
+ };
289
+
290
+ return _Class;
291
+
292
+ })();
293
+
294
+ }).call(this);
295
+ }, "presenter": function(exports, require, module) {(function() {
296
+ var FailedAssertMessageResolver;
297
+
298
+ FailedAssertMessageResolver = require('./failed_assert_message_resolver');
299
+
300
+ module.exports = (function() {
301
+
302
+ function _Class(tests, options) {
303
+ var Test, _i, _len, _ref;
304
+ var _this = this;
305
+ this.tests = tests;
306
+ this.options = options;
307
+ this.completed = 0;
308
+ this.succeeded_asserts = 0;
309
+ this.failed_asserts = 0;
310
+ this.asserts = 0;
311
+ _ref = this.tests;
312
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
313
+ Test = _ref[_i];
314
+ Test.bind('runCompleted', function(test_run) {
315
+ return _this.handleCompletedRun(test_run);
316
+ });
317
+ Test.bind('completed', function() {
318
+ return _this.checkComplete();
319
+ });
320
+ }
321
+ }
322
+
323
+ _Class.prototype.handleCompletedRun = function(run) {
324
+ var failed_assert, _i, _len, _ref, _results;
325
+ this.asserts += run.failed_asserts.length + run.succeeded_asserts_count;
326
+ this.failed_asserts += run.failed_asserts.length;
327
+ this.succeeded_asserts += run.succeeded_asserts_count;
328
+ _ref = run.failed_asserts;
329
+ _results = [];
330
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
331
+ failed_assert = _ref[_i];
332
+ _results.push(this.outputFailedAssert(failed_assert));
333
+ }
334
+ return _results;
335
+ };
336
+
337
+ _Class.prototype.checkComplete = function() {
338
+ this.completed += 1;
339
+ if (this.completed === this.tests.length) return this.complete();
340
+ };
341
+
342
+ _Class.prototype.failedAssertDescription = function(failed_assert) {
343
+ return "" + failed_assert.run.constructor.name + "[" + failed_assert.run.method_name + "]: " + (this.failedAssertMessage(failed_assert));
344
+ };
345
+
346
+ _Class.prototype.failedAssertMessage = function(failed_assert) {
347
+ return new FailedAssertMessageResolver(failed_assert).message();
348
+ };
349
+
350
+ _Class.prototype.summaryMessage = function() {
351
+ return "COMPLETE: " + this.asserts + " asserts, " + this.failed_asserts + " failed, " + this.succeeded_asserts + " succeeded";
352
+ };
353
+
354
+ return _Class;
355
+
356
+ })();
357
+
358
+ }).call(this);
359
+ }, "runner": function(exports, require, module) {
360
+ module.exports = (function() {
361
+
362
+ function _Class(options) {
363
+ this.options = options;
364
+ }
365
+
366
+ _Class.prototype.run = function() {
367
+ var Test, _i, _len, _ref, _results;
368
+ new this.presenter_class(this.tests(), this.options);
369
+ _ref = this.tests();
370
+ _results = [];
371
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
372
+ Test = _ref[_i];
373
+ _results.push(Test.runAll());
374
+ }
375
+ return _results;
376
+ };
377
+
378
+ return _Class;
379
+
380
+ })();
381
+ }, "test_case": function(exports, require, module) {(function() {
382
+ var Assertsions, EventEmitter, Utils;
383
+
384
+ Assertsions = require('./assertions');
385
+
386
+ EventEmitter = require('./event_emitter');
387
+
388
+ Utils = require('./utils');
389
+
390
+ module.exports = (function() {
391
+
392
+ _Class.runs = [];
393
+
394
+ _Class.runAll = function() {
395
+ var method_name, _i, _len, _ref, _results;
396
+ this.completed = 0;
397
+ if (this.testMethodNames().length > 0) {
398
+ _ref = this.testMethodNames();
399
+ _results = [];
400
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
401
+ method_name = _ref[_i];
402
+ _results.push(this.run(method_name));
403
+ }
404
+ return _results;
405
+ } else {
406
+ return this.complete();
407
+ }
408
+ };
409
+
410
+ _Class.run = function(method_name) {
411
+ var run;
412
+ var _this = this;
413
+ run = new this(method_name);
414
+ run.bind('completed', function() {
415
+ return _this.runCompleted(run);
416
+ });
417
+ run.run();
418
+ return this.runs.push(run);
419
+ };
420
+
421
+ _Class.runCompleted = function(run) {
422
+ this.trigger('runCompleted', run);
423
+ this.completed += 1;
424
+ if (this.completed === this.testMethodNames().length) return this.complete();
425
+ };
426
+
427
+ _Class.complete = function() {
428
+ return this.trigger('completed');
429
+ };
430
+
431
+ _Class.testMethodNames = function() {
432
+ var method_name, _i, _len, _ref, _results;
433
+ _ref = Object.keys(this.prototype);
434
+ _results = [];
435
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
436
+ method_name = _ref[_i];
437
+ if (method_name.substr(0, 5) === 'test ' || this.methodNameIsAsync(method_name)) {
438
+ _results.push(method_name);
439
+ }
440
+ }
441
+ return _results;
442
+ };
443
+
444
+ _Class.methodNameIsAsync = function(method_name) {
445
+ return method_name.substr(0, 11) === 'async test ';
446
+ };
447
+
448
+ function _Class(method_name) {
449
+ this.method_name = method_name;
450
+ this.succeeded_asserts_count = 0;
451
+ this.failed_asserts = [];
452
+ }
453
+
454
+ _Class.prototype.run = function() {
455
+ if (this.setup) this.setup();
456
+ this[this.method_name]();
457
+ if (this.teardown) this.teardown();
458
+ if (!this.async()) return this.complete();
459
+ };
460
+
461
+ _Class.prototype.async = function() {
462
+ return this.constructor.methodNameIsAsync(this.method_name);
463
+ };
464
+
465
+ _Class.prototype.complete = function() {
466
+ this.completed = true;
467
+ return this.trigger('completed');
468
+ };
469
+
470
+ _Class.prototype.store_assert = function(type, succeeded, options) {
471
+ if (options == null) options = {};
472
+ if (succeeded) {
473
+ return this.succeeded_asserts_count += 1;
474
+ } else {
475
+ return this.failed_asserts.push({
476
+ type: type,
477
+ succeeded: succeeded,
478
+ options: options,
479
+ run: this
480
+ });
481
+ }
482
+ };
483
+
484
+ _Class.prototype.succeeded = function() {
485
+ return this.completed && this.failed_asserts === 0;
486
+ };
487
+
488
+ return _Class;
489
+
490
+ })();
491
+
492
+ Utils.extend(module.exports.prototype, Assertsions);
493
+
494
+ Utils.extend(module.exports.prototype, EventEmitter);
495
+
496
+ Utils.extend(module.exports, EventEmitter);
497
+
498
+ }).call(this);
499
+ }, "utils": function(exports, require, module) {
500
+ module.exports = {
501
+ extend: function(obj1, obj2) {
502
+ var key, value, _results;
503
+ _results = [];
504
+ for (key in obj2) {
505
+ value = obj2[key];
506
+ _results.push(obj1[key] = value);
507
+ }
508
+ return _results;
509
+ }
510
+ };
511
+ }});
512
+
513
+ }).call(window.Janitor.Stitch);
514
+ window.Janitor.TestCase = Janitor.Stitch.require('test_case'),
515
+ window.Janitor.BrowserRunner = Janitor.Stitch.require('browser_runner')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janitor_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,7 +16,16 @@ email: rasmusrnielsen@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
- files: []
19
+ files:
20
+ - lib/janitor_rails/engine.rb
21
+ - lib/janitor_rails.rb
22
+ - app/controllers/janitor_rails/application_controller.rb
23
+ - app/controllers/janitor_rails/test_controller.rb
24
+ - app/views/janitor_rails/test/index.html.erb
25
+ - config/initializers/add_asset_path.rb
26
+ - config/routes.rb
27
+ - vendor/assets/javascripts/janitor.js
28
+ - init.rb
20
29
  homepage:
21
30
  licenses: []
22
31
  post_install_message: