janitor_rails 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/vendor/assets/javascripts/janitor.js +124 -83
  2. metadata +2 -2
@@ -53,20 +53,24 @@ window.Janitor.Stitch = {};
53
53
  return this.require.define;
54
54
  }).call(this)({"assertions": function(exports, require, module) {
55
55
  module.exports = {
56
- assertEqual: function(expected, actual) {
56
+ equal: function(expected, actual) {
57
57
  var success;
58
58
  success = expected === actual;
59
- return this.storeAssert('equal', success, {
59
+ return {
60
+ success: success,
60
61
  expected: expected,
61
62
  actual: actual
62
- });
63
+ };
63
64
  },
64
- assert: function(exp) {
65
- return this.storeAssert('true', exp, {
66
- exp: exp
67
- });
65
+ truthy: function(value) {
66
+ var success;
67
+ success = !!value;
68
+ return {
69
+ success: success,
70
+ value: value
71
+ };
68
72
  },
69
- assertThrows: function(callback, check) {
73
+ throws: function(callback, check) {
70
74
  var caught, error, success;
71
75
  caught = false;
72
76
  error = null;
@@ -77,61 +81,41 @@ window.Janitor.Stitch = {};
77
81
  error = thrownError;
78
82
  }
79
83
  success = caught && (!check || check(error));
80
- return this.storeAssert('throw', success, {
84
+ return {
85
+ success: success,
81
86
  callback: callback,
82
87
  error: error
83
- });
88
+ };
84
89
  },
85
- refuteThrows: function(callback) {
86
- var caught, error, success;
87
- caught = false;
88
- error = null;
89
- try {
90
- callback();
91
- } catch (thrownError) {
92
- caught = true;
93
- error = thrownError;
94
- }
95
- success = !caught;
96
- return this.storeAssert('refuteThrow', success, {
97
- callback: callback,
98
- error: error
99
- });
100
- },
101
- assertContains: function(container, value) {
102
- var result;
103
- result = container.indexOf(value) !== -1;
104
- return this.storeAssert('contains', result, {
90
+ contains: function(container, value) {
91
+ var success;
92
+ success = container.indexOf(value) !== -1;
93
+ return {
94
+ success: success,
105
95
  container: container,
106
96
  value: value
107
- });
97
+ };
108
98
  },
109
- assertAll: function(enumerable, callback) {
99
+ all: function(enumerable, callback) {
110
100
  var success;
111
101
  success = true;
112
102
  enumerable.forEach(function(item) {
113
103
  if (success) return success = callback(item);
114
104
  });
115
- return this.storeAssert('all', success, {
105
+ return {
106
+ success: success,
116
107
  callback: callback
117
- });
108
+ };
118
109
  },
119
- assertInDelta: function(expected, actual, delta) {
110
+ inDelta: function(expected, actual, delta) {
120
111
  var success;
121
112
  success = expected - delta < actual && expected + delta > actual;
122
- return this.storeAssert('inDelta', success, {
113
+ return {
114
+ success: success,
123
115
  expected: expected,
124
116
  actual: actual,
125
117
  delta: delta
126
- });
127
- },
128
- refuteEqual: function(expected, actual) {
129
- var success;
130
- success = expected !== actual;
131
- return this.storeAssert('refuteEqual', success, {
132
- expected: expected,
133
- actual: actual
134
- });
118
+ };
135
119
  }
136
120
  };
137
121
  }, "browser_presenter": function(exports, require, module) {(function() {
@@ -250,39 +234,48 @@ window.Janitor.Stitch = {};
250
234
  }
251
235
  };
252
236
  }, "failed_assertion_message": function(exports, require, module) {(function() {
253
- var FailedAssertionMessage;
237
+ var FailedAssertionMessage, Utils;
238
+
239
+ Utils = require('./utils');
254
240
 
255
241
  module.exports = FailedAssertionMessage = (function() {
256
242
 
257
243
  function FailedAssertionMessage(failedAssert) {
258
244
  this.type = failedAssert.type;
259
- this.options = failedAssert.options;
245
+ this.result = failedAssert.result;
246
+ this.refutation = failedAssert.refutation;
260
247
  }
261
248
 
262
- FailedAssertionMessage.prototype.equal = function() {
263
- return "" + this.options.actual + " does not equal " + this.options.expected;
249
+ FailedAssertionMessage.prototype.assertEqual = function() {
250
+ return "" + this.result.actual + " does not equal " + this.result.expected;
264
251
  };
265
252
 
266
- FailedAssertionMessage.prototype["true"] = function() {
267
- return "" + this.options.exp + " is not true";
253
+ FailedAssertionMessage.prototype.assertInDelta = function() {
254
+ return "" + this.result.actual + " is not within " + this.result.expected + "±" + this.result.delta;
268
255
  };
269
256
 
270
- FailedAssertionMessage.prototype.inDelta = function() {
271
- return "" + this.options.actual + " is not within " + this.options.expected + "±" + this.options.delta;
257
+ FailedAssertionMessage.prototype.refuteEqual = function() {
258
+ return "" + this.result.actual + " equals " + this.result.expected;
272
259
  };
273
260
 
274
- FailedAssertionMessage.prototype.refuteEqual = function() {
275
- return "" + this.options.actual + " equals " + this.options.expected;
261
+ FailedAssertionMessage.prototype.assertTruthy = function() {
262
+ return "" + this.result.value + " is not true";
276
263
  };
277
264
 
278
265
  FailedAssertionMessage.prototype.toString = function() {
279
- if (this[this.type]) {
280
- return this[this.type]();
266
+ if (this[this.methodName()]) {
267
+ return this[this.methodName()]();
281
268
  } else {
282
269
  return "Unknown assert fail: " + this.type;
283
270
  }
284
271
  };
285
272
 
273
+ FailedAssertionMessage.prototype.methodName = function() {
274
+ var prefix;
275
+ prefix = this.refutation ? 'refute' : 'assert';
276
+ return prefix + Utils.firstToUpper(this.type);
277
+ };
278
+
286
279
  return FailedAssertionMessage;
287
280
 
288
281
  })();
@@ -406,7 +399,7 @@ window.Janitor.Stitch = {};
406
399
 
407
400
  _Class.prototype.run = function() {
408
401
  var Test, _i, _len, _ref, _results;
409
- new this.presenterClass(this.tests(), this.options);
402
+ new this.presenterClass(this.activeTests(), this.options);
410
403
  _ref = this.tests();
411
404
  _results = [];
412
405
  for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -416,23 +409,34 @@ window.Janitor.Stitch = {};
416
409
  return _results;
417
410
  };
418
411
 
412
+ _Class.prototype.activeTests = function() {
413
+ var soloTest, tests;
414
+ tests = this.tests();
415
+ soloTest = null;
416
+ tests.forEach(function(test) {
417
+ if (test.solo) return soloTest = test;
418
+ });
419
+ return soloTest || tests;
420
+ };
421
+
419
422
  return _Class;
420
423
 
421
424
  })();
422
425
  }, "test_case": function(exports, require, module) {(function() {
423
- var Assertsions, EventEmitter, Utils;
426
+ var Assertions, EventEmitter, TestCase, Utils, key, _i, _len, _ref;
427
+ var __slice = Array.prototype.slice;
424
428
 
425
- Assertsions = require('./assertions');
429
+ Assertions = require('./assertions');
426
430
 
427
431
  EventEmitter = require('./event_emitter');
428
432
 
429
433
  Utils = require('./utils');
430
434
 
431
- module.exports = (function() {
435
+ TestCase = (function() {
432
436
 
433
- _Class.runs = [];
437
+ TestCase.runs = [];
434
438
 
435
- _Class.runAll = function() {
439
+ TestCase.runAll = function() {
436
440
  var methodName, _i, _len, _ref, _results;
437
441
  this.completed = 0;
438
442
  if (this.testMethodNames().length > 0) {
@@ -448,7 +452,7 @@ window.Janitor.Stitch = {};
448
452
  }
449
453
  };
450
454
 
451
- _Class.run = function(methodName) {
455
+ TestCase.run = function(methodName) {
452
456
  var run;
453
457
  var _this = this;
454
458
  run = new this(methodName);
@@ -459,17 +463,17 @@ window.Janitor.Stitch = {};
459
463
  return this.runs.push(run);
460
464
  };
461
465
 
462
- _Class.runCompleted = function(run) {
466
+ TestCase.runCompleted = function(run) {
463
467
  this.trigger('runCompleted', run);
464
468
  this.completed += 1;
465
469
  if (this.completed === this.testMethodNames().length) return this.complete();
466
470
  };
467
471
 
468
- _Class.complete = function() {
472
+ TestCase.complete = function() {
469
473
  return this.trigger('completed');
470
474
  };
471
475
 
472
- _Class.testMethodNames = function() {
476
+ TestCase.testMethodNames = function() {
473
477
  var methodName, _i, _len, _ref, _results;
474
478
  _ref = Object.keys(this.prototype);
475
479
  _results = [];
@@ -482,59 +486,91 @@ window.Janitor.Stitch = {};
482
486
  return _results;
483
487
  };
484
488
 
485
- _Class.methodNameIsAsync = function(methodName) {
489
+ TestCase.methodNameIsAsync = function(methodName) {
486
490
  return methodName.substr(0, 11) === 'async test ';
487
491
  };
488
492
 
489
- function _Class(methodName) {
493
+ TestCase.addAssertionMethods = function(type) {
494
+ this.addAssertionMethod(type);
495
+ return this.addAssertionMethod(type, true);
496
+ };
497
+
498
+ TestCase.addAssertionMethod = function(type, refutation) {
499
+ var name, prefix, suffix;
500
+ prefix = refutation ? 'refute' : 'assert';
501
+ suffix = type === 'truthy' ? '' : Utils.firstToUpper(type);
502
+ name = prefix + suffix;
503
+ return this.prototype[name] = function() {
504
+ var args;
505
+ args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
506
+ return this.runAssertion(type, {
507
+ args: args,
508
+ refutation: refutation
509
+ });
510
+ };
511
+ };
512
+
513
+ function TestCase(methodName) {
490
514
  this.methodName = methodName;
491
515
  this.succeededAssertsCount = 0;
492
516
  this.failedAsserts = [];
493
517
  }
494
518
 
495
- _Class.prototype.run = function() {
519
+ TestCase.prototype.run = function() {
496
520
  if (this.setup) this.setup();
497
521
  this[this.methodName]();
498
522
  if (this.teardown) this.teardown();
499
- if (!this.async()) return this.complete();
523
+ if (!this.isAsync()) return this.complete();
500
524
  };
501
525
 
502
- _Class.prototype.async = function() {
526
+ TestCase.prototype.isAsync = function() {
503
527
  return this.constructor.methodNameIsAsync(this.methodName);
504
528
  };
505
529
 
506
- _Class.prototype.complete = function() {
530
+ TestCase.prototype.complete = function() {
507
531
  this.completed = true;
508
532
  return this.trigger('completed');
509
533
  };
510
534
 
511
- _Class.prototype.storeAssert = function(type, succeeded, options) {
512
- if (options == null) options = {};
513
- if (succeeded) {
535
+ TestCase.prototype.storeAssert = function(type, refutation, result) {
536
+ if (result.success) {
514
537
  return this.succeededAssertsCount += 1;
515
538
  } else {
516
539
  return this.failedAsserts.push({
517
540
  type: type,
518
- succeeded: succeeded,
519
- options: options,
541
+ refutation: refutation,
542
+ result: result,
520
543
  run: this
521
544
  });
522
545
  }
523
546
  };
524
547
 
525
- _Class.prototype.succeeded = function() {
548
+ TestCase.prototype.succeeded = function() {
526
549
  return this.completed && this.failedAsserts === 0;
527
550
  };
528
551
 
529
- return _Class;
552
+ TestCase.prototype.runAssertion = function(type, options) {
553
+ var result;
554
+ result = Assertions[type].apply(null, options.args);
555
+ if (options.refutation) result.success = !result.succes;
556
+ return this.storeAssert(type, options.refutation, result);
557
+ };
558
+
559
+ return TestCase;
530
560
 
531
561
  })();
532
562
 
533
- Utils.extend(module.exports.prototype, Assertsions);
563
+ _ref = Object.keys(Assertions);
564
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
565
+ key = _ref[_i];
566
+ TestCase.addAssertionMethods(key);
567
+ }
568
+
569
+ Utils.extend(TestCase.prototype, EventEmitter);
534
570
 
535
- Utils.extend(module.exports.prototype, EventEmitter);
571
+ Utils.extend(TestCase, EventEmitter);
536
572
 
537
- Utils.extend(module.exports, EventEmitter);
573
+ module.exports = TestCase;
538
574
 
539
575
  }).call(this);
540
576
  }, "utils": function(exports, require, module) {
@@ -547,6 +583,11 @@ window.Janitor.Stitch = {};
547
583
  _results.push(obj1[key] = value);
548
584
  }
549
585
  return _results;
586
+ },
587
+ firstToUpper: function(text) {
588
+ return text.replace(/.{1}/, function(v) {
589
+ return v.toUpperCase();
590
+ });
550
591
  }
551
592
  };
552
593
  }});
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.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 Z
12
+ date: 2012-04-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: janitor_rails lets you easily test Javascript code with Janitor.
15
15
  email: rasmusrnielsen@gmail.com