konacha 2.0.0.beta2 → 2.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1462,14 +1462,22 @@ exports.list = function(failures){
1462
1462
  , index = stack.indexOf(message) + message.length
1463
1463
  , msg = stack.slice(0, index)
1464
1464
  , actual = err.actual
1465
- , expected = err.expected;
1465
+ , expected = err.expected
1466
+ , escape = true;
1467
+
1468
+ // explicitly show diff
1469
+ if (err.showDiff) {
1470
+ escape = false;
1471
+ err.actual = actual = JSON.stringify(actual, null, 2);
1472
+ err.expected = expected = JSON.stringify(expected, null, 2);
1473
+ }
1466
1474
 
1467
1475
  // actual / expected diff
1468
1476
  if ('string' == typeof actual && 'string' == typeof expected) {
1469
1477
  var len = Math.max(actual.length, expected.length);
1470
1478
 
1471
- if (len < 20) msg = errorDiff(err, 'Chars');
1472
- else msg = errorDiff(err, 'Words');
1479
+ if (len < 20) msg = errorDiff(err, 'Chars', escape);
1480
+ else msg = errorDiff(err, 'Words', escape);
1473
1481
 
1474
1482
  // linenos
1475
1483
  var lines = msg.split('\n');
@@ -1645,12 +1653,14 @@ function pad(str, len) {
1645
1653
  * @api private
1646
1654
  */
1647
1655
 
1648
- function errorDiff(err, type) {
1656
+ function errorDiff(err, type, escape) {
1649
1657
  return diff['diff' + type](err.actual, err.expected).map(function(str){
1650
- str.value = str.value
1651
- .replace(/\t/g, '<tab>')
1652
- .replace(/\r/g, '<CR>')
1653
- .replace(/\n/g, '<LF>\n');
1658
+ if (escape) {
1659
+ str.value = str.value
1660
+ .replace(/\t/g, '<tab>')
1661
+ .replace(/\r/g, '<CR>')
1662
+ .replace(/\n/g, '<LF>\n');
1663
+ }
1654
1664
  if (str.added) return colorLines('diff added', str.value);
1655
1665
  if (str.removed) return colorLines('diff removed', str.value);
1656
1666
  return str.value;
@@ -1936,15 +1946,19 @@ function HTML(runner, root) {
1936
1946
  if (!root) return error('#mocha div missing, add it to your document');
1937
1947
 
1938
1948
  // pass toggle
1939
- on(passesLink, 'click', function () {
1940
- var className = /pass/.test(report.className) ? '' : ' pass';
1941
- report.className = report.className.replace(/fail|pass/g, '') + className;
1949
+ on(passesLink, 'click', function(){
1950
+ unhide();
1951
+ var name = /pass/.test(report.className) ? '' : ' pass';
1952
+ report.className = report.className.replace(/fail|pass/g, '') + name;
1953
+ if (report.className.trim()) hideSuitesWithout('test pass');
1942
1954
  });
1943
1955
 
1944
1956
  // failure toggle
1945
- on(failuresLink, 'click', function () {
1946
- var className = /fail/.test(report.className) ? '' : ' fail';
1947
- report.className = report.className.replace(/fail|pass/g, '') + className;
1957
+ on(failuresLink, 'click', function(){
1958
+ unhide();
1959
+ var name = /fail/.test(report.className) ? '' : ' fail';
1960
+ report.className = report.className.replace(/fail|pass/g, '') + name;
1961
+ if (report.className.trim()) hideSuitesWithout('test fail');
1948
1962
  });
1949
1963
 
1950
1964
  root.appendChild(stat);
@@ -2060,6 +2074,30 @@ function fragment(html) {
2060
2074
  return div.firstChild;
2061
2075
  }
2062
2076
 
2077
+ /**
2078
+ * Check for suites that do not have elements
2079
+ * with `classname`, and hide them.
2080
+ */
2081
+
2082
+ function hideSuitesWithout(classname) {
2083
+ var suites = document.getElementsByClassName('suite');
2084
+ for (var i = 0; i < suites.length; i++) {
2085
+ var els = suites[i].getElementsByClassName(classname);
2086
+ if (0 == els.length) suites[i].className += ' hidden';
2087
+ }
2088
+ }
2089
+
2090
+ /**
2091
+ * Unhide .hidden suites.
2092
+ */
2093
+
2094
+ function unhide() {
2095
+ var els = document.getElementsByClassName('suite hidden');
2096
+ for (var i = 0; i < els.length; ++i) {
2097
+ els[i].className = els[i].className.replace('suite hidden', 'suite');
2098
+ }
2099
+ }
2100
+
2063
2101
  /**
2064
2102
  * Set `el` text to `str`.
2065
2103
  */
@@ -3752,8 +3790,16 @@ Runner.prototype.globals = function(arr){
3752
3790
 
3753
3791
  Runner.prototype.checkGlobals = function(test){
3754
3792
  if (this.ignoreLeaks) return;
3755
- var leaks = filterLeaks(this._globals);
3793
+ var ok = this._globals;
3794
+ var globals = keys(global);
3795
+ var isNode = process.kill;
3796
+ var leaks;
3797
+
3798
+ // check length - 2 ('errno' and 'location' globals)
3799
+ if (isNode && 1 == ok.length - globals.length) return
3800
+ else if (2 == ok.length - globals.length) return;
3756
3801
 
3802
+ leaks = filterLeaks(ok, globals);
3757
3803
  this._globals = this._globals.concat(leaks);
3758
3804
 
3759
3805
  if (leaks.length > 1) {
@@ -4105,12 +4151,13 @@ Runner.prototype.run = function(fn){
4105
4151
  * Filter leaks with the given globals flagged as `ok`.
4106
4152
  *
4107
4153
  * @param {Array} ok
4154
+ * @param {Array} globals
4108
4155
  * @return {Array}
4109
4156
  * @api private
4110
4157
  */
4111
4158
 
4112
- function filterLeaks(ok) {
4113
- return filter(keys(global), function(key){
4159
+ function filterLeaks(ok, globals) {
4160
+ return filter(globals, function(key){
4114
4161
  var matched = filter(ok, function(ok){
4115
4162
  if (~ok.indexOf('*')) return 0 == key.indexOf(ok.split('*')[0]);
4116
4163
  return key == ok;
@@ -37,6 +37,10 @@ body {
37
37
  font-size: .8em;
38
38
  }
39
39
 
40
+ .hidden {
41
+ display: none;
42
+ }
43
+
40
44
  #mocha h2 {
41
45
  font-size: 12px;
42
46
  font-weight: normal;
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konacha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta2
4
+ version: 2.0.0.beta3
5
5
  prerelease: 6
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-10-02 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -228,6 +228,11 @@ files:
228
228
  - konacha.gemspec
229
229
  - lib/konacha.rb
230
230
  - lib/konacha/engine.rb
231
+ - lib/konacha/formatter.rb
232
+ - lib/konacha/reporter.rb
233
+ - lib/konacha/reporter/example.rb
234
+ - lib/konacha/reporter/example_group.rb
235
+ - lib/konacha/reporter/metadata.rb
231
236
  - lib/konacha/runner.rb
232
237
  - lib/konacha/server.rb
233
238
  - lib/tasks/konacha.rake
@@ -259,8 +264,13 @@ files:
259
264
  - spec/dummy/spec/javascripts/templating_spec.js
260
265
  - spec/dummy/spec/javascripts/ui_spec.js
261
266
  - spec/error_handling_spec.rb
267
+ - spec/formatter_spec.rb
262
268
  - spec/konacha_spec.rb
263
269
  - spec/models/spec_spec.rb
270
+ - spec/reporter/example_group_spec.rb
271
+ - spec/reporter/example_spec.rb
272
+ - spec/reporter/metadata_spec.rb
273
+ - spec/reporter_spec.rb
264
274
  - spec/runner_spec.rb
265
275
  - spec/server_spec.rb
266
276
  - spec/spec_helper.rb
@@ -281,6 +291,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
281
291
  - - ! '>='
282
292
  - !ruby/object:Gem::Version
283
293
  version: '0'
294
+ segments:
295
+ - 0
296
+ hash: -1614270189281322721
284
297
  required_rubygems_version: !ruby/object:Gem::Requirement
285
298
  none: false
286
299
  requirements:
@@ -289,7 +302,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
302
  version: 1.3.1
290
303
  requirements: []
291
304
  rubyforge_project:
292
- rubygems_version: 1.8.23
305
+ rubygems_version: 1.8.24
293
306
  signing_key:
294
307
  specification_version: 3
295
308
  summary: Unit-test your Rails JavaScript with the mocha test framework and chai assertion
@@ -323,8 +336,13 @@ test_files:
323
336
  - spec/dummy/spec/javascripts/templating_spec.js
324
337
  - spec/dummy/spec/javascripts/ui_spec.js
325
338
  - spec/error_handling_spec.rb
339
+ - spec/formatter_spec.rb
326
340
  - spec/konacha_spec.rb
327
341
  - spec/models/spec_spec.rb
342
+ - spec/reporter/example_group_spec.rb
343
+ - spec/reporter/example_spec.rb
344
+ - spec/reporter/metadata_spec.rb
345
+ - spec/reporter_spec.rb
328
346
  - spec/runner_spec.rb
329
347
  - spec/server_spec.rb
330
348
  - spec/spec_helper.rb