btakita-screw_unit 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/CHANGES +4 -1
  2. data/README.markdown +347 -0
  3. data/core/EXAMPLE.html +68 -0
  4. data/core/LICENSE +22 -0
  5. data/core/README.markdown +223 -23
  6. data/core/example/models/cat.js +5 -0
  7. data/core/example/models/man.js +17 -0
  8. data/core/example/spec/matchers/have.js +8 -0
  9. data/core/example/spec/models/cat_spec.js +31 -0
  10. data/core/example/spec/models/man_spec.js +34 -0
  11. data/core/example/spec/spec_helper.js +5 -0
  12. data/core/example/spec/suite.html +25 -0
  13. data/core/lib/jquery.print.js +103 -19
  14. data/core/lib/screw.behaviors.js +1 -1
  15. data/core/lib/screw.builder.js +7 -8
  16. data/core/lib/screw.css +25 -28
  17. data/core/lib/screw.events.js +4 -5
  18. data/core/lib/screw.matchers.js +3 -3
  19. data/core/spec/matchers_spec.js +6 -6
  20. data/core/spec/print_spec.js +119 -0
  21. data/{vendor/js_test_core/spec/example_core/JsTestCore.css → core/spec/spec_helper.js} +0 -0
  22. data/core/spec/suite.html +2 -1
  23. data/lib/screw_unit.rb +1 -1
  24. data/spec/functional/functional_spec.rb +1 -1
  25. data/vendor/{js_test_core → js-test-core}/CHANGES +0 -0
  26. data/vendor/{js_test_core → js-test-core}/README +0 -0
  27. data/vendor/{js_test_core → js-test-core}/Rakefile +0 -0
  28. data/vendor/{js_test_core → js-test-core}/lib/js_test_core.rb +0 -0
  29. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/client.rb +0 -0
  30. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/rack.rb +0 -0
  31. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/rack/commonlogger.rb +0 -0
  32. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/rails_server.rb +0 -0
  33. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources.rb +1 -0
  34. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/dir.rb +0 -0
  35. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/file.rb +0 -0
  36. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +15 -0
  37. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/runners.rb +0 -0
  38. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/runners/firefox_runner.rb +4 -2
  39. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/specs/spec_dir.rb +0 -0
  40. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/specs/spec_file.rb +0 -0
  41. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/suite.rb +0 -0
  42. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/suite_finish.rb +0 -0
  43. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/resources/web_root.rb +10 -2
  44. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/selenium.rb +0 -0
  45. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/selenium/selenium_driver.rb +0 -0
  46. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/server.rb +0 -0
  47. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/thin.rb +0 -0
  48. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/thin/backends/js_test_core_server.rb +0 -0
  49. data/vendor/{js_test_core → js-test-core}/lib/js_test_core/thin/js_test_core_connection.rb +0 -0
  50. data/vendor/{js_test_core/spec/example_core/JsTestCore.js → js-test-core/spec/example_core/JsTestCore.css} +0 -0
  51. data/vendor/{js_test_core/spec/example_public/favicon.ico → js-test-core/spec/example_core/JsTestCore.js} +0 -0
  52. data/vendor/{js_test_core/spec/example_public/robots.txt → js-test-core/spec/example_public/favicon.ico} +0 -0
  53. data/vendor/{js_test_core → js-test-core}/spec/example_public/javascripts/foo.js +0 -0
  54. data/vendor/{js_test_core/spec/specs/failing_spec.js → js-test-core/spec/example_public/robots.txt} +0 -0
  55. data/vendor/{js_test_core → js-test-core}/spec/example_public/stylesheets/example.css +0 -0
  56. data/vendor/{js_test_core → js-test-core}/spec/example_specs/failing_spec.js +0 -0
  57. data/vendor/{js_test_core → js-test-core}/spec/example_specs/foo/failing_spec.js +0 -0
  58. data/vendor/{js_test_core → js-test-core}/spec/example_specs/foo/passing_spec.js +0 -0
  59. data/vendor/{js_test_core → js-test-core}/spec/spec_suite.rb +0 -0
  60. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  61. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/client_spec.rb +0 -0
  62. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/rails_server_spec.rb +0 -0
  63. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/dir_spec.rb +0 -0
  64. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +26 -0
  65. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/file_spec.rb +0 -0
  66. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/runner_spec.rb +0 -0
  67. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/runners/firefox_runner_spec.rb +36 -0
  68. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/specs/spec_dir_spec.rb +0 -0
  69. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/specs/spec_file_spec.rb +0 -0
  70. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/suite_finish_spec.rb +0 -0
  71. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/resources/suite_spec.rb +0 -0
  72. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +103 -0
  73. data/vendor/{js_test_core/spec/unit/js_spec → js-test-core/spec/unit/js_test_core}/server_spec.rb +0 -0
  74. data/vendor/{js_test_core → js-test-core}/spec/unit/thin/js_test_core_connection_spec.rb +0 -0
  75. data/vendor/{js_test_core → js-test-core}/spec/unit/unit_spec_helper.rb +0 -0
  76. data/vendor/{js_test_core → js-test-core}/spec/unit_suite.rb +0 -0
  77. metadata +95 -77
  78. data/README +0 -147
  79. data/vendor/js_test_core/spec/unit/js_spec/resources/web_root_spec.rb +0 -67
  80. data/vendor/js_test_core/spec/unit/thin/js_spec_connection_spec.rb +0 -64
@@ -0,0 +1,5 @@
1
+ function Cat(options) {
2
+ this.cross_path = function(man) {
3
+ if (options.color == 'black') man.decrement_luck(5);
4
+ };
5
+ }
@@ -0,0 +1,17 @@
1
+ function Man(options) {
2
+ var luck = options.luck;
3
+
4
+ this.decrement_luck = function(delta) {
5
+ luck = Math.max(0, luck - delta);
6
+ };
7
+ this.luck = function() {
8
+ return luck;
9
+ };
10
+ this.render = function() {
11
+ return $('<ul class="man">')
12
+ .append('<li class="hair">')
13
+ .click(function() {
14
+ $(this).children('.hair').remove();
15
+ });
16
+ };
17
+ }
@@ -0,0 +1,8 @@
1
+ Screw.Matchers["have"] = {
2
+ match: function(expected, actual) {
3
+ return actual.find(expected).length > 0;
4
+ },
5
+ failure_message: function(expected, actual, not) {
6
+ return 'expected ' + $.print(actual) + (not ? ' to not have ' : ' to have ') + $.print(expected);
7
+ }
8
+ }
@@ -0,0 +1,31 @@
1
+ Screw.Unit(function() {
2
+ describe('Cat', function() {
3
+ var cat;
4
+
5
+ describe('#cross_path', function() {
6
+ describe('when the cat has black fur', function() {
7
+ before(function() {
8
+ cat = new Cat({color: 'black'});
9
+ });
10
+
11
+ it("decrements the man's luck by 5", function() {
12
+ var man = new Man({luck: 5});
13
+ cat.cross_path(man);
14
+ expect(man.luck()).to(equal, 0);
15
+ });
16
+ });
17
+
18
+ describe('when the cat has non-black fur', function() {
19
+ before(function() {
20
+ cat = new Cat({color: 'white'});
21
+ });
22
+
23
+ it("does not change the man's luck", function() {
24
+ var man = new Man({luck: 5});
25
+ cat.cross_path(man);
26
+ expect(man.luck()).to(equal, 5);
27
+ });
28
+ });
29
+ });
30
+ });
31
+ });
@@ -0,0 +1,34 @@
1
+ Screw.Unit(function() {
2
+ describe('Man', function() {
3
+ var man;
4
+ before(function() {
5
+ man = new Man({luck: 5});
6
+ });
7
+
8
+ describe('#decrement_luck', function() {
9
+ it("decrements the luck field by the given amount", function() {
10
+ man.decrement_luck(3);
11
+ expect(man.luck()).to(equal, 2)
12
+ });
13
+
14
+ describe('when the decrement exceeds the luck balance', function() {
15
+ it("decrements the luck field to zero", function() {
16
+ man.decrement_luck(10000000000);
17
+ expect(man.luck()).to(equal, 0);
18
+ });
19
+ });
20
+ });
21
+
22
+ describe('@click', function() {
23
+ before(function() {
24
+ $('#dom_test').append(man.render());
25
+ });
26
+
27
+ it("removes the man's hair", function() {
28
+ expect($('.man')).to(have, '.hair');
29
+ $('.man').click();
30
+ expect($('.man')).to_not(have, '.hair');
31
+ });
32
+ });
33
+ });
34
+ });
@@ -0,0 +1,5 @@
1
+ Screw.Unit(function() {
2
+ before(function() {
3
+ $('dom_test').empty();
4
+ });
5
+ });
@@ -0,0 +1,25 @@
1
+ <html>
2
+ <head>
3
+ <script src="../../lib/jquery-1.2.3.js"></script>
4
+ <script src="../../lib/jquery.fn.js"></script>
5
+ <script src="../../lib/jquery.print.js"></script>
6
+ <script src="../../lib/screw.builder.js"></script>
7
+ <script src="../../lib/screw.matchers.js"></script>
8
+ <script src="../../lib/screw.events.js"></script>
9
+ <script src="../../lib/screw.behaviors.js"></script>
10
+
11
+ <script src="spec_helper.js"></script>
12
+ <script src="matchers/have.js"></script>
13
+
14
+ <script src="../models/cat.js"></script>
15
+ <script src="../models/man.js"></script>
16
+
17
+ <script src="models/cat_spec.js"></script>
18
+ <script src="models/man_spec.js"></script>
19
+
20
+ <link rel="stylesheet" href="../../lib/screw.css">
21
+ </head>
22
+ <body>
23
+ <div id="dom_test" style="position: absolute; left: -9999"></div>
24
+ </body>
25
+ </html>
@@ -1,24 +1,108 @@
1
1
  (function($) {
2
- $.print = function(obj) {
3
- if (obj instanceof Function) {
4
- return obj.toString().match(/^([^\{]*) {/)[1];
5
- } else if(obj instanceof Array) {
6
- var result = [];
7
- for (var i = 0; i < obj.length; i++) {
8
- result.push($.print(obj[i]));
9
- }
10
- return "[" + result.join(", ") + "]";
11
- } else if(obj instanceof HTMLElement) {
12
- return "<" + obj.tagName + " " + (obj.className != "" ? "class='" + obj.className + "'" : "") +
13
- (obj.id != "" ? "id='" + obj.id + "'" : "") + ">";
14
- } else if(obj instanceof Object) {
2
+
3
+ function print_array(obj, opts) {
4
+ var result = [];
5
+ for (var i = 0; i < Math.min(opts.max_array, obj.length); i++)
6
+ result.push($.print(obj[i], $.extend({}, opts, { max_array: 3, max_string: 40 })));
7
+
8
+ if (obj.length > opts.max_array)
9
+ result.push((obj.length - opts.max_array) + ' more...');
10
+ if (result.length == 0) return "[]"
11
+ return "[ " + result.join(", ") + " ]";
12
+ }
13
+
14
+ function print_element(obj) {
15
+ if (obj.nodeType == 1) {
15
16
  var result = [];
16
- for (var k in obj) {
17
- result.push(k + ": " + $.print(obj[k]))
18
- }
19
- return "{" + result.join(", ") + "}"
20
- } else {
21
- return obj.toString().replace(/\n\s*/g, "");
17
+ var properties = [ 'className', 'id' ];
18
+ var extra = {
19
+ 'input': ['type', 'name', 'value'],
20
+ 'a': ['href', 'target'],
21
+ 'form': ['method', 'action']
22
+ };
23
+ $.each(properties.concat(extra[obj.tagName.toLowerCase()] || []), function() {
24
+ if (obj[this])
25
+ result.push(' ' + this.replace('className', 'class') + "=" + $.print(obj[this]))
26
+ });
27
+ return "<" + obj.tagName.toLowerCase()
28
+ + result.join('') + ">";
29
+ }
30
+ }
31
+
32
+ function print_object(obj, opts) {
33
+ var seen = opts.seen || [];
34
+
35
+ var result = [], key, value;
36
+ for (var k in obj) {
37
+ if (obj.hasOwnProperty(k) && $.inArray(obj[k], seen) < 0) {
38
+ seen.push(obj[k]);
39
+ value = $.print(obj[k], $.extend({}, opts, { max_array: 6, max_string: 40, seen: seen }));
40
+ } else
41
+ value = "...";
42
+ result.push(k + ": " + value);
22
43
  }
44
+ if (result.length == 0) return "{}";
45
+ return "{ " + result.join(", ") + " }";
46
+ }
47
+
48
+ function print_jquery(obj) {
49
+ }
50
+
51
+ function print_string(value, opts) {
52
+ var character_substitutions = {
53
+ '\b': '\\b',
54
+ '\t': '\\t',
55
+ '\n': '\\n',
56
+ '\f': '\\f',
57
+ '\r': '\\r',
58
+ '"' : '\\"',
59
+ '\\': '\\\\'
60
+ };
61
+ var r = /["\\\x00-\x1f\x7f-\x9f]/g;
62
+
63
+ var str = r.test(value)
64
+ ? '"' + value.replace(r, function (a) {
65
+ var c = character_substitutions[a];
66
+ if (c) return c;
67
+ c = a.charCodeAt();
68
+ return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
69
+ }) + '"'
70
+ : '"' + value + '"';
71
+ if (str.length > opts.max_string)
72
+ return str.slice(0, opts.max_string + 1) + '..."';
73
+ else
74
+ return str;
75
+ }
76
+
77
+ $.print = function(obj, options) {
78
+ var opts = $.extend({}, { max_array: 10, max_string: 100 }, options);
79
+
80
+ if (typeof obj == 'undefined')
81
+ return "undefined";
82
+ else if (typeof obj == 'boolean')
83
+ return obj.toString();
84
+ else if (!obj && typeof obj == 'number')
85
+ return 'NaN';
86
+ else if (!obj)
87
+ return "null";
88
+ else if (typeof obj == 'string')
89
+ return print_string(obj, opts);
90
+ else if (obj instanceof RegExp)
91
+ return obj.toString();
92
+ else if (typeof obj == 'function' || obj instanceof Function)
93
+ return obj.toString().match(/^([^)]*\))/)[1];
94
+ else if (obj instanceof Array)
95
+ return print_array(obj, opts);
96
+ else if (obj.nodeType)
97
+ return print_element(obj);
98
+ else if (obj instanceof jQuery)
99
+ return "$(" + $.print(obj.get()) + ")";
100
+ else if (obj instanceof Error)
101
+ return print_object(obj, $.extend({}, options, { max_string: 200 }));
102
+ else if (obj instanceof Object)
103
+ return print_object(obj, opts);
104
+ else
105
+ return obj.toString().replace(/\n\s*/g, '');
23
106
  }
107
+
24
108
  })(jQuery);
@@ -1,5 +1,5 @@
1
1
  (function($) {
2
- $(Screw).bind('load', function() {
2
+ $(Screw).bind('loaded', function() {
3
3
  $('.status').fn({
4
4
  display: function() {
5
5
  $(this).text(
@@ -18,13 +18,12 @@ var Screw = (function($) {
18
18
  context: [],
19
19
 
20
20
  describe: function(name, fn) {
21
- var describe = $('<li class="describe">');
22
- $('<h1>').text(name).appendTo(describe);
23
- describe
21
+ var describe = $('<li class="describe">')
22
+ .append($('<h1>').text(name))
24
23
  .append('<ol class="befores">')
25
24
  .append('<ul class="its">')
26
25
  .append('<ul class="describes">')
27
- .append('<ol class="afters">')
26
+ .append('<ol class="afters">');
28
27
 
29
28
  this.context.push(describe);
30
29
  fn.call();
@@ -36,9 +35,9 @@ var Screw = (function($) {
36
35
  },
37
36
 
38
37
  it: function(name, fn) {
39
- var it = $('<li class="it">');
40
- $('<h2>').text(name).appendTo(it);
41
- it.data('screwunit.run', fn);
38
+ var it = $('<li class="it">')
39
+ .append($('<h2>').text(name))
40
+ .data('screwunit.run', fn);
42
41
 
43
42
  this.context[this.context.length-1]
44
43
  .children('.its')
@@ -75,7 +74,7 @@ var Screw = (function($) {
75
74
  .appendTo('body');
76
75
 
77
76
  $(screw).dequeue();
78
- $(screw).trigger('load');
77
+ $(screw).trigger('loaded');
79
78
  });
80
79
  return screw;
81
80
  })(jQuery);
data/core/lib/screw.css CHANGED
@@ -3,19 +3,19 @@ html {
3
3
  font-family: Georgia, serif;
4
4
  background: #EDEBD5;
5
5
  }
6
-
6
+
7
7
  li {
8
8
  list-style-type: none;
9
9
  }
10
-
10
+
11
11
  .focused {
12
12
  background-color: #F4F2E4;
13
13
  }
14
-
14
+
15
15
  .focused * {
16
16
  opacity: 1.0;
17
17
  }
18
-
18
+
19
19
  h1, h2, p {
20
20
  opacity: 0.4;
21
21
  }
@@ -23,7 +23,7 @@ html {
23
23
  .describes {
24
24
  padding-left: 0;
25
25
  }
26
-
26
+
27
27
  .describes h1 {
28
28
  font-size: 1.1em;
29
29
  color: #877C21;
@@ -31,7 +31,7 @@ html {
31
31
  margin: 0pt 0pt 0.6em;
32
32
  border-bottom: 1px solid transparent;
33
33
  }
34
-
34
+
35
35
  .describes h1:hover {
36
36
  cursor: pointer;
37
37
  color: #000;
@@ -44,50 +44,47 @@ html {
44
44
  padding-left: 0.6em;
45
45
  border: 1px dashed grey;
46
46
  }
47
-
47
+
48
48
  .describes .describe .its {}
49
49
 
50
50
  .describes .describe .its .it {
51
51
  list-style-type: lower-roman;
52
52
  list-style-position: outside;
53
53
  }
54
-
54
+
55
55
  .describes .describe .its .it h2 {
56
56
  font-weight: normal;
57
57
  font-style: italic;
58
58
  padding-left: 0.5em;
59
+ font-size: 1.0em;
60
+ color: #877C21;
61
+ line-height: 1.8em;
62
+ margin: 0 0 0.5em;
63
+ border-bottom: 1px solid transparent;
59
64
  }
60
65
 
61
66
  .describes .describe .its .it.enqueued h2 {
62
67
  background-color: #CC6600;
63
- color: white;
68
+ color: white !important;
64
69
  }
65
70
 
66
71
  .describes .describe .its .it.passed h2 {
67
72
  background-color: #5A753D;
68
- color: white;
73
+ color: white !important;
69
74
  }
70
75
 
71
76
  .describes .describe .its .it.failed h2 {
72
77
  background-color: #993300;
73
- color: white;
78
+ color: white !important;
74
79
  }
75
-
76
- .describes .describe .its .it.failed p {
77
- margin-left: 1em;
78
- color: #993300;
79
- }
80
-
81
- .describes .describe .its .it h2 {
82
- font-size: 1.0em;
83
- color: #877C21;
84
- line-height: 1.8em;
85
- margin: 0 0 0.5em;
86
- border-bottom: 1px solid transparent;
80
+
81
+ .describes .describe .its .it.failed p {
82
+ margin-left: 1em;
83
+ color: #993300;
87
84
  }
88
85
 
89
- .describes .describe .its .it h2:hover {
90
- cursor: pointer;
91
- color: #000;
92
- border-bottom: 1px solid #9A8E51;
93
- }
86
+ .describes .describe .its .it h2:hover {
87
+ cursor: pointer;
88
+ color: #000 !important;
89
+ border-bottom: 1px solid #9A8E51;
90
+ }
@@ -1,6 +1,6 @@
1
1
  (function($) {
2
2
  $(Screw)
3
- .bind('load', function() {
3
+ .bind('loaded', function() {
4
4
  $('.describe, .it')
5
5
  .click(function() {
6
6
  document.location = location.href.split('?')[0] + '?' + $(this).fn('selector');
@@ -24,10 +24,9 @@
24
24
  $(this).addClass('passed');
25
25
  })
26
26
  .bind('failed', function(e, reason) {
27
- $(this).addClass('failed');
28
- $('<p class="error">')
29
- .text(reason.toString())
30
- .appendTo($(this));
27
+ $(this)
28
+ .addClass('failed')
29
+ .append($('<p class="error">').text(reason.toString()));
31
30
  })
32
31
  })
33
32
  .bind('before', function() {