extjs-mvc 0.3.10 → 0.4.0.a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.rdoc +5 -173
  3. data/Rakefile +18 -20
  4. data/VERSION +1 -1
  5. data/bin/xmvc +13 -0
  6. data/lib/extjs-mvc/README +20 -0
  7. data/lib/extjs-mvc/builder.rb +83 -0
  8. data/lib/extjs-mvc/builders/all_builder.rb +15 -0
  9. data/lib/extjs-mvc/builders/app_builder.rb +36 -0
  10. data/lib/extjs-mvc/builders/base.rb +138 -0
  11. data/lib/extjs-mvc/builders/css_builder.rb +36 -0
  12. data/lib/extjs-mvc/builders/docs_builder.rb +20 -0
  13. data/lib/extjs-mvc/builders/mvc_builder.rb +33 -0
  14. data/lib/extjs-mvc/builders/plugin_builder.rb +53 -0
  15. data/lib/extjs-mvc/cli.rb +52 -0
  16. data/lib/extjs-mvc/generator.rb +79 -0
  17. data/lib/extjs-mvc/generators/app.rb +57 -0
  18. data/lib/extjs-mvc/generators/base.rb +53 -0
  19. data/lib/extjs-mvc/generators/controller.rb +41 -0
  20. data/lib/extjs-mvc/generators/model.rb +41 -0
  21. data/lib/extjs-mvc/generators/scaffold.rb +17 -0
  22. data/lib/extjs-mvc/generators/templates/Controller.js +17 -0
  23. data/lib/extjs-mvc/generators/templates/Model.js +9 -0
  24. data/lib/extjs-mvc/generators/templates/ModelSpec.js +12 -0
  25. data/lib/extjs-mvc/generators/templates/View.js +16 -0
  26. data/lib/extjs-mvc/generators/templates/_Action.js +7 -0
  27. data/lib/extjs-mvc/generators/templates/app/README.rdoc +152 -0
  28. data/lib/extjs-mvc/generators/templates/app/app/App.js +64 -0
  29. data/lib/extjs-mvc/generators/templates/app/app/controllers/ApplicationController.js +10 -0
  30. data/lib/extjs-mvc/generators/templates/app/app/controllers/HomeController.js +10 -0
  31. data/lib/extjs-mvc/generators/templates/app/app/views/home/Index.js +17 -0
  32. data/lib/extjs-mvc/generators/templates/app/app/views/layout/Menu.js +23 -0
  33. data/lib/extjs-mvc/generators/templates/app/config/application.js +1 -0
  34. data/lib/extjs-mvc/generators/templates/app/config/boot.js +67 -0
  35. data/lib/extjs-mvc/generators/templates/app/config/build.xml +77 -0
  36. data/lib/extjs-mvc/generators/templates/app/config/database.js +4 -0
  37. data/lib/extjs-mvc/generators/templates/app/config/environment.json +58 -0
  38. data/lib/extjs-mvc/generators/templates/app/config/environments/development.json +1 -0
  39. data/lib/extjs-mvc/generators/templates/app/config/environments/production.json +4 -0
  40. data/lib/extjs-mvc/generators/templates/app/config/routes.js +27 -0
  41. data/lib/extjs-mvc/generators/templates/app/config/settings.yml +3 -0
  42. data/lib/extjs-mvc/generators/templates/app/public/index.html +19 -0
  43. data/lib/extjs-mvc/generators/templates/app/public/stylesheets/ext-mvc-all.css +49 -0
  44. data/{test/active_record_test.rb → lib/extjs-mvc/generators/templates/app/spec/SpecHelper.js} +0 -0
  45. data/lib/extjs-mvc/generators/templates/app/spec/index.html +66 -0
  46. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/EXAMPLE.html +68 -0
  47. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/LICENSE +22 -0
  48. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/README.markdown +307 -0
  49. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  50. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.fn.js +29 -0
  51. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/jquery.print.js +108 -0
  52. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.assets.js +36 -0
  53. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  54. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.builder.js +80 -0
  55. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.css +90 -0
  56. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.events.js +42 -0
  57. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.matchers.js +145 -0
  58. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/lib/screw.server.js +21 -0
  59. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  60. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/matchers_spec.js +237 -0
  61. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/print_spec.js +119 -0
  62. data/{test/controller_test.rb → lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/spec_helper.js} +0 -0
  63. data/lib/extjs-mvc/generators/templates/app/vendor/screw-unit/spec/suite.html +18 -0
  64. data/lib/extjs-mvc/generators/templates/scaffold/ScaffoldController.js +18 -0
  65. data/lib/extjs-mvc/generators/view.rb +29 -0
  66. data/lib/extjs-mvc/plugin.rb +105 -0
  67. data/lib/extjs-mvc/scripts.rb +15 -0
  68. data/lib/extjs-mvc/settings.rb +75 -0
  69. data/lib/extjs-mvc/setup.rb +5 -0
  70. data/lib/extjs-mvc/stats.rb +241 -0
  71. data/lib/extjs-mvc/test.rb +11 -0
  72. data/lib/extjs-mvc/testserver.ru +95 -0
  73. data/lib/extjs-mvc/ui.rb +58 -0
  74. data/lib/extjs-mvc/update.rb +73 -0
  75. data/lib/extjs-mvc.rb +70 -32
  76. data/lib/js/App.js +219 -0
  77. data/lib/js/MVC.js +260 -0
  78. data/lib/js/Presenter.js +52 -0
  79. data/lib/js/README.rdoc +69 -0
  80. data/lib/js/build +21 -0
  81. data/lib/js/controller/Controller.js +278 -0
  82. data/lib/js/controller/CrudController.js +460 -0
  83. data/lib/js/lib/Array.js +26 -0
  84. data/lib/js/lib/Booter.js +415 -0
  85. data/lib/js/lib/ClassManager.js +191 -0
  86. data/lib/js/lib/ControllerClassManager.js +95 -0
  87. data/lib/js/lib/Dependencies.js +44 -0
  88. data/lib/js/lib/DispatchMatcher.js +98 -0
  89. data/lib/js/lib/Dispatcher.js +129 -0
  90. data/lib/js/lib/Environment.js +43 -0
  91. data/lib/js/lib/Inflector.js +138 -0
  92. data/lib/js/lib/ModelClassManager.js +19 -0
  93. data/lib/js/lib/Route.js +139 -0
  94. data/lib/js/lib/Router.js +282 -0
  95. data/lib/js/lib/String.js +94 -0
  96. data/lib/js/lib/ViewClassManager.js +229 -0
  97. data/lib/js/lib/notes.txt +32 -0
  98. data/lib/js/model/AdapterManager.js +30 -0
  99. data/lib/js/model/Association.js +26 -0
  100. data/lib/js/model/Base.js +63 -0
  101. data/lib/js/model/BelongsToAssociation.js +116 -0
  102. data/lib/js/model/Cache.js +131 -0
  103. data/lib/js/model/HasManyAssociation.js +160 -0
  104. data/lib/js/model/Model.js +331 -0
  105. data/lib/js/model/UrlBuilder.js +106 -0
  106. data/lib/js/model/adapters/AbstractAdapter.js +296 -0
  107. data/lib/js/model/adapters/MemoryAdapter.js +103 -0
  108. data/lib/js/model/adapters/RESTAdapter.js +345 -0
  109. data/lib/js/model/adapters/RESTJSONAdapter.js +68 -0
  110. data/lib/js/model/adapters/notes.txt +42 -0
  111. data/lib/js/model/associations/Association.js +192 -0
  112. data/lib/js/model/associations/notes.txt +87 -0
  113. data/lib/js/model/validations/Errors.js +136 -0
  114. data/lib/js/model/validations/Plugin.js +139 -0
  115. data/lib/js/model/validations/Validations.js +276 -0
  116. data/lib/js/notes/Charts.graffle +0 -0
  117. data/lib/js/overrides/Ext.Component.js +21 -0
  118. data/lib/js/overrides/Ext.extend.js +142 -0
  119. data/lib/js/spec/Array.spec.js +15 -0
  120. data/lib/js/spec/ExtMVC.spec.js +65 -0
  121. data/lib/js/spec/Model.spec.js +370 -0
  122. data/lib/js/spec/OS.spec.js +83 -0
  123. data/lib/js/spec/Router.spec.js +99 -0
  124. data/lib/js/spec/SpecHelper.js +106 -0
  125. data/lib/js/spec/String.spec.js +83 -0
  126. data/lib/js/spec/model/AbstractAdapter.spec.js +49 -0
  127. data/lib/js/spec/model/Associations.spec.js +99 -0
  128. data/lib/js/spec/model/Cache.spec.js +5 -0
  129. data/lib/js/spec/model/RESTAdapter.spec.js +19 -0
  130. data/lib/js/spec/model/ValidationErrors.spec.js +64 -0
  131. data/lib/js/spec/model/Validations.spec.js +166 -0
  132. data/lib/js/spec/model/ValidationsPlugin.spec.js +108 -0
  133. data/lib/js/spec/suite.html +60 -0
  134. data/lib/js/specs-old/JSSpec.css +216 -0
  135. data/lib/js/specs-old/JSSpec.js +1512 -0
  136. data/lib/js/specs-old/all.html +66 -0
  137. data/lib/js/specs-old/base.js +14 -0
  138. data/lib/js/specs-old/controller.js +17 -0
  139. data/lib/js/specs-old/diff_match_patch.js +1 -0
  140. data/lib/js/specs-old/model.js +70 -0
  141. data/lib/js/specs-old/route.js +38 -0
  142. data/lib/js/specs-old/router.js +59 -0
  143. data/lib/js/specs-old/string.js +22 -0
  144. data/lib/js/testrunner/JSpecFormatter.js +111 -0
  145. data/lib/js/testrunner/TestClient.js +181 -0
  146. data/lib/js/testrunner/TestGrid.js +351 -0
  147. data/lib/js/testrunner/TestRunner.js +110 -0
  148. data/lib/js/testrunner/TestViewport.js +94 -0
  149. data/lib/js/vendor/screw-unit/EXAMPLE.html +68 -0
  150. data/lib/js/vendor/screw-unit/LICENSE +22 -0
  151. data/lib/js/vendor/screw-unit/README.markdown +307 -0
  152. data/lib/js/vendor/screw-unit/lib/jquery-1.2.3.js +3408 -0
  153. data/lib/js/vendor/screw-unit/lib/jquery.fn.js +29 -0
  154. data/lib/js/vendor/screw-unit/lib/jquery.print.js +108 -0
  155. data/lib/js/vendor/screw-unit/lib/screw.assets.js +36 -0
  156. data/lib/js/vendor/screw-unit/lib/screw.behaviors.js +91 -0
  157. data/lib/js/vendor/screw-unit/lib/screw.builder.js +80 -0
  158. data/lib/js/vendor/screw-unit/lib/screw.css +91 -0
  159. data/lib/js/vendor/screw-unit/lib/screw.events.js +42 -0
  160. data/lib/js/vendor/screw-unit/lib/screw.matchers.js +145 -0
  161. data/lib/js/vendor/screw-unit/lib/screw.server.js +21 -0
  162. data/lib/js/vendor/screw-unit/spec/behaviors_spec.js +178 -0
  163. data/lib/js/vendor/screw-unit/spec/matchers_spec.js +237 -0
  164. data/lib/js/vendor/screw-unit/spec/print_spec.js +119 -0
  165. data/{test/data_mapper_test.rb → lib/js/vendor/screw-unit/spec/spec_helper.js} +0 -0
  166. data/lib/js/vendor/screw-unit/spec/suite.html +18 -0
  167. data/lib/js/view/FormWindow.js +184 -0
  168. data/lib/js/view/HasManyEditorGridPanel.js +211 -0
  169. data/lib/js/view/scaffold/Edit.js +46 -0
  170. data/lib/js/view/scaffold/Index.js +561 -0
  171. data/lib/js/view/scaffold/New.js +20 -0
  172. data/lib/js/view/scaffold/ScaffoldFormPanel.js +255 -0
  173. data/test/helper.rb +10 -0
  174. data/test/test_extjs-mvc-gem.rb +7 -0
  175. metadata +232 -56
  176. data/README +0 -12
  177. data/lib/controller/controller.rb +0 -28
  178. data/lib/core_ext/array/extract_options.rb +0 -15
  179. data/lib/extjs/component.rb +0 -71
  180. data/lib/extjs/data/store.rb +0 -131
  181. data/lib/helpers/component.rb +0 -37
  182. data/lib/helpers/store.rb +0 -7
  183. data/lib/model/active_record.rb +0 -89
  184. data/lib/model/base.rb +0 -370
  185. data/lib/model/data_mapper.rb +0 -66
  186. data/lib/model/mongo_mapper.rb +0 -64
  187. data/lib/test/macros.rb +0 -20
  188. data/test/app/config/application.rb +0 -70
  189. data/test/app/config/database.yml +0 -3
  190. data/test/app/db/schema.rb +0 -75
  191. data/test/app/models/active_record/address.rb +0 -4
  192. data/test/app/models/active_record/data_type.rb +0 -3
  193. data/test/app/models/active_record/group.rb +0 -4
  194. data/test/app/models/active_record/house.rb +0 -4
  195. data/test/app/models/active_record/location.rb +0 -5
  196. data/test/app/models/active_record/person.rb +0 -4
  197. data/test/app/models/active_record/user.rb +0 -6
  198. data/test/app/models/active_record/user_group.rb +0 -4
  199. data/test/component_test.rb +0 -15
  200. data/test/debug.log +0 -2969
  201. data/test/model_test.rb +0 -526
  202. data/test/mongo_mapper_test.rb +0 -0
  203. data/test/store_test.rb +0 -0
  204. data/test/test_helper.rb +0 -32
@@ -0,0 +1,178 @@
1
+ Screw.Unit(function() {
2
+ var global_before_invoked = false, global_after_invoked = false;
3
+ before(function() { global_before_invoked = true });
4
+ after(function() { global_after_invoked = true });
5
+
6
+ describe('Behaviors', function() {
7
+ describe('#run', function() {
8
+ describe("a simple [describe]", function() {
9
+ it("invokes the global [before] before an [it]", function() {
10
+ expect(global_before_invoked).to(equal, true);
11
+ global_before_invoked = false;
12
+ });
13
+
14
+ it("invokes the global [before] before each [it]", function() {
15
+ expect(global_before_invoked).to(equal, true);
16
+ global_after_invoked = false;
17
+ });
18
+
19
+ it("invokes the global [after] after an [it]", function() {
20
+ expect(global_after_invoked).to(equal, true);
21
+ });
22
+ });
23
+
24
+ describe("a [describe] with a [before] and [after] block", function() {
25
+ var before_invoked = false, after_invoked = false;
26
+ before(function() { before_invoked = true });
27
+ after(function() { after_invoked = true });
28
+
29
+ describe('[after] blocks', function() {
30
+ it("does not invoke the [after] until after the first [it]", function() {
31
+ expect(after_invoked).to(equal, false);
32
+ });
33
+
34
+ it("invokes the [after] after the first [it]", function() {
35
+ expect(after_invoked).to(equal, true);
36
+ after_invoked = false;
37
+ });
38
+
39
+ it("invokes the [after] after each [it]", function() {
40
+ expect(after_invoked).to(equal, true);
41
+ });
42
+ });
43
+
44
+ describe('[before] blocks', function() {
45
+ it("invokes the [before] before an it", function() {
46
+ expect(before_invoked).to(equal, true);
47
+ before_invoked = false;
48
+ });
49
+
50
+ it("invokes the [before] before each it", function() {
51
+ expect(before_invoked).to(equal, true);
52
+ });
53
+ });
54
+ });
55
+
56
+ describe("A [describe] with two [before] and two [after] blocks", function() {
57
+ var before_invocations = [], after_invocations = [];
58
+ before(function() { before_invocations.push('before 1') });
59
+ before(function() { before_invocations.push('before 2') });
60
+
61
+ after(function() { after_invocations.push('after 1') });
62
+ after(function() { after_invocations.push('after 2') });
63
+
64
+ it("invokes the [before]s in lexical order before each [it]", function() {
65
+ expect(before_invocations).to(equal, ['before 1', 'before 2']);
66
+ });
67
+
68
+ it("invokes the [afters]s in lexical order after each [it]", function() {
69
+ expect(after_invocations).to(equal, ['after 1', 'after 2']);
70
+ });
71
+ });
72
+
73
+ describe("A describe with a nested describe", function() {
74
+ var before_invocations = [], after_invocations = [];
75
+ before(function() {
76
+ before_invocations = [];
77
+ before_invocations.push("outermost before");
78
+ });
79
+
80
+ after(function() {
81
+ after_invocations = [];
82
+ after_invocations.push("outermost after");
83
+ });
84
+
85
+ it("outside a nested [describe], does not invoke any of the nested's [before]s", function() {
86
+ expect(before_invocations).to(equal, ["outermost before"]);
87
+ });
88
+
89
+ it("outside a nested [describe], does not invoke any of the nested's [after]s", function() {
90
+ expect(after_invocations).to(equal, ["outermost after"]);
91
+ });
92
+
93
+ describe("a nested [describe]", function() {
94
+ before(function() {
95
+ before_invocations.push("inner before");
96
+ });
97
+
98
+ after(function() {
99
+ after_invocations.push("inner after");
100
+ });
101
+
102
+ it("runs [before]s in the parent [describe] before each [it]", function() {
103
+ expect(before_invocations).to(equal, ["outermost before", "inner before"]);
104
+ });
105
+
106
+ it("runs [after]s in the parent [describe] after each [it]", function() {
107
+ expect(after_invocations).to(equal, ["outermost after", "inner after"]);
108
+ });
109
+
110
+ describe("a doubly nested [describe]", function() {
111
+ before(function() {
112
+ before_invocations.push('innermost before');
113
+ });
114
+
115
+ after(function() {
116
+ after_invocations.push('innermost after');
117
+ });
118
+
119
+ describe('[before] blocks', function() {
120
+ it("runs [before]s in all ancestors before an [it]", function() {
121
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
122
+ });
123
+
124
+ it("runs [before]s in all ancestors before each [it]", function() {
125
+ expect(before_invocations).to(equal, ["outermost before", "inner before", "innermost before"]);
126
+ });
127
+ });
128
+
129
+ describe('[after] blocks', function() {
130
+ it("runs [after]s in all ancestors after an [it]", function() {
131
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
132
+ });
133
+
134
+ it("runs [after]s in all ancestors after each [it]", function() {
135
+ expect(after_invocations).to(equal, ["outermost after", "inner after", "innermost after"]);
136
+ });
137
+ });
138
+ });
139
+ });
140
+ });
141
+
142
+ describe("A describe block with exceptions", function() {
143
+ var after_invoked = false;
144
+ after(function() {
145
+ after_invoked = true;
146
+ });
147
+
148
+ describe("an exception in a test", function() {
149
+ it("fails because it throws an exception", function() {
150
+ throw('an exception');
151
+ });
152
+
153
+ it("invokes [after]s even if the previous [it] raised an exception", function() {
154
+ expect(after_invoked).to(equal, true);
155
+ });
156
+ });
157
+ });
158
+ });
159
+
160
+ describe("#selector", function() {
161
+ describe('a [describe]', function() {
162
+ it('manufactures a CSS selector that uniquely locates the [describe]', function() {
163
+ $('.describe').each(function() {
164
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
165
+ });
166
+ });
167
+ });
168
+
169
+ describe('an [it]', function() {
170
+ it('manufactures a CSS selector that uniquely locates the [it]', function() {
171
+ $('.it').each(function() {
172
+ expect($($(this).fn('selector')).get(0)).to(equal, $(this).get(0))
173
+ });
174
+ });
175
+ });
176
+ });
177
+ });
178
+ });
@@ -0,0 +1,237 @@
1
+ Screw.Unit(function() {
2
+ describe("Matchers", function() {
3
+ describe('#equal', function() {
4
+ it("invokes the provided matcher on a call to expect", function() {
5
+ expect(true).to(equal, true);
6
+ expect(true).to_not(equal, false);
7
+ });
8
+
9
+ describe('when given an object', function() {
10
+ it("matches Objects with the same keys and values", function() {
11
+ expect({a: 'b', c: 'd'}).to(equal, {a: 'b', c: 'd'});
12
+ expect({a: 'b', c: 'd', e: 'f'}).to_not(equal, {a: 'b', c: 'd', e: 'G'});
13
+ });
14
+
15
+ });
16
+
17
+ describe('when given an array', function() {
18
+ it("matches Arrays with the same elements", function() {
19
+ expect([1, 2, 4]).to(equal, [1, 2, 4]);
20
+ expect([1, 2, 3]).to_not(equal, [3, 2, 1]);
21
+ });
22
+
23
+ it("recursively applies equality to complex elements", function() {
24
+ expect([{a: 'b'}, {c: 'd'}]).to(equal, [{a: 'b'}, {c: 'd'}]);
25
+ expect([{a: 'b'}, {c: 'd'}]).to_not(equal, [{a: 'b'}, {c: 'E'}]);
26
+ });
27
+ });
28
+
29
+ describe(".failure_message", function() {
30
+ it('prints "expected [expected] to (not) be equal [actual]"', function() {
31
+ var message = null;
32
+ try { expect(1).to(equal, 2) } catch(e) { message = e }
33
+ expect(message).to(equal, 'expected 1 to equal 2');
34
+
35
+ try { expect(1).to_not(equal, 1) } catch(e) { message = e }
36
+ expect(message).to(equal, 'expected 1 to not equal 1');
37
+ });
38
+ });
39
+ });
40
+
41
+ describe('#match', function() {
42
+ describe('when given a regular expression', function() {
43
+ it("matches Strings produced by the grammar", function() {
44
+ expect("The wheels of the bus").to(match, /bus/);
45
+ expect("The wheels of the bus").to_not(match, /boat/);
46
+ });
47
+ });
48
+
49
+ describe('when given a string', function() {
50
+ it("matches [expected]s containing [actual]s", function() {
51
+ expect("The wheels of the bus").to(match, "wheels");
52
+ expect("The wheels of the bus").to_not(match, "oars");
53
+ });
54
+ });
55
+
56
+ describe('when given an integer', function() {
57
+ it("matches [expected]s containing [actual]s", function() {
58
+ expect("1 time").to(match, 1);
59
+ expect("2 times").to_not(match, 3);
60
+ });
61
+ });
62
+
63
+ describe(".failure_message", function() {
64
+ it('prints "expected [actual] to (not) match [expected]', function() {
65
+ var message = null;
66
+ try { expect("hello").to(match, "schmello") } catch(e) { message = e }
67
+ expect(message).to(equal, 'expected "hello" to match "schmello"');
68
+
69
+ try { expect("hello").to_not(match, "ello") } catch(e) { message = e }
70
+ expect(message).to(equal, 'expected "hello" to not match "ello"');
71
+ });
72
+ });
73
+ });
74
+
75
+ describe('#be_empty', function() {
76
+ it("matches Arrays with no elements", function() {
77
+ expect([]).to(be_empty);
78
+ expect([1]).to_not(be_empty);
79
+ });
80
+
81
+ describe(".failure_message", function() {
82
+ it("prints 'expected [actual] to (not) be empty", function() {
83
+ var message = null;
84
+ try { expect([1]).to(be_empty) } catch(e) { message = e }
85
+ expect(message).to(equal, 'expected [ 1 ] to be empty');
86
+
87
+ try { expect([]).to_not(be_empty) } catch(e) { message = e }
88
+ expect(message).to(equal, 'expected [] to not be empty');
89
+ });
90
+ });
91
+ });
92
+
93
+ describe('#have_length', function() {
94
+ it("matches Arrays of the expected length", function() {
95
+ expect([]).to(have_length, 0);
96
+ expect([1]).to(have_length, 1);
97
+ expect([1, 2, 3]).to_not(have_length, 4);
98
+ });
99
+
100
+ describe(".failure_message", function() {
101
+ it("prints 'expected [actual] to (not) have length [expected]", function() {
102
+ var message = null;
103
+ try { expect([1, 2]).to(have_length, 4) } catch(e) { message = e }
104
+ expect(message).to(equal, 'expected [ 1, 2 ] to have length 4');
105
+
106
+ try { expect([1]).to_not(have_length, 1) } catch(e) { message = e }
107
+ expect(message).to(equal, 'expected [ 1 ] to not have length 1');
108
+ });
109
+ });
110
+ });
111
+
112
+ describe('#be_null', function() {
113
+ it("matches null", function() {
114
+ expect(null).to(be_null);
115
+ expect(1).to_not(be_null);
116
+ });
117
+
118
+ describe(".failure_message", function() {
119
+ it("prints 'expected [actual] to (not) be null", function() {
120
+ var message = null;
121
+ try { expect(1).to(be_null) } catch(e) { message = e }
122
+ expect(message).to(equal, 'expected 1 to be null');
123
+
124
+ try { expect(null).to_not(be_null) } catch(e) { message = e }
125
+ expect(message).to(equal, 'expected null to not be null');
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('#be_undefined', function() {
131
+ it("matches undefined", function() {
132
+ expect(undefined).to(be_undefined);
133
+ expect(1).to_not(be_undefined);
134
+ });
135
+
136
+ describe(".failure_message", function() {
137
+ it("prints 'expected [actual] to (not) be undefined", function() {
138
+ var message = undefined;
139
+ try { expect(1).to(be_undefined) } catch(e) { message = e }
140
+ expect(message).to(equal, 'expected 1 to be undefined');
141
+
142
+ try { expect(undefined).to_not(be_undefined) } catch(e) { message = e }
143
+ expect(message).to(equal, 'expected undefined to not be undefined');
144
+ });
145
+ });
146
+ });
147
+
148
+ describe('#be_true', function() {
149
+ it("matches values that are considered true conditions", function() {
150
+ expect(true).to(be_true);
151
+ expect(1).to(be_true);
152
+ expect(false).to_not(be_true);
153
+ expect(undefined).to_not(be_true);
154
+ expect(null).to_not(be_true);
155
+ });
156
+
157
+ describe(".failure_message", function() {
158
+ it("prints 'expected [actual] to (not) be true", function() {
159
+ var message = true;
160
+ try { expect(false).to(be_true) } catch(e) { message = e }
161
+ expect(message).to(equal, 'expected false to be true');
162
+
163
+ try { expect(true).to_not(be_true) } catch(e) { message = e }
164
+ expect(message).to(equal, 'expected true to not be true');
165
+ });
166
+ });
167
+ });
168
+
169
+ describe('#be_false', function() {
170
+ it("matches values that are considered false conditions", function() {
171
+ expect(false).to(be_false);
172
+ expect(undefined).to(be_false);
173
+ expect(null).to(be_false);
174
+ expect(true).to_not(be_false);
175
+ expect(1).to_not(be_false);
176
+ });
177
+
178
+ describe(".failure_message", function() {
179
+ it("prints 'expected [actual] to (not) be false", function() {
180
+ var message = false;
181
+ try { expect(true).to(be_false) } catch(e) { message = e }
182
+ expect(message).to(equal, 'expected true to be false');
183
+
184
+ try { expect(false).to_not(be_false) } catch(e) { message = e }
185
+ expect(message).to(equal, 'expected false to not be false');
186
+ });
187
+ });
188
+ });
189
+
190
+ describe('#match_selector', function() {
191
+ var elt;
192
+ before(function() {
193
+ elt = $("<div class='foo'></div>");
194
+ });
195
+
196
+ it("matches a jQuery element against the expected selector", function() {
197
+ expect(elt).to(match_selector, 'div.foo');
198
+ expect(elt).to_not(match_selector, 'div.bar');
199
+ });
200
+
201
+ describe(".failure_message", function() {
202
+ it("prints 'expected [actual] to (not) match selector [expected]", function() {
203
+ var message = false;
204
+ try { expect(elt).to(match_selector, 'div.bar') } catch(e) { message = e }
205
+ expect(message).to(equal, 'expected $([ <div class="foo"> ]) to match selector div.bar');
206
+
207
+ try { expect(elt).to_not(match_selector, 'div.foo') } catch(e) { message = e }
208
+ expect(message).to(equal, 'expected $([ <div class="foo"> ]) to not match selector div.foo');
209
+ });
210
+ });
211
+ });
212
+
213
+ describe('#contain_selector', function() {
214
+ var elt;
215
+ before(function() {
216
+ elt = $("<div><div class='foo'></div></div>");
217
+ });
218
+
219
+ it("matches a jQuery element against the expected selector", function() {
220
+ expect(elt).to(contain_selector, 'div.foo');
221
+ expect(elt).to_not(contain_selector, 'div.bar');
222
+ });
223
+
224
+ describe(".failure_message", function() {
225
+ it("prints 'expected [actual] to (not) match selector [expected]", function() {
226
+ var message = false;
227
+ try { expect(elt).to(contain_selector, 'div.bar') } catch(e) { message = e }
228
+ expect(message).to(equal, 'expected $([ <div> ]) to contain selector div.bar');
229
+
230
+ try { expect(elt).to_not(contain_selector, 'div.foo') } catch(e) { message = e }
231
+ expect(message).to(equal, 'expected $([ <div> ]) to not contain selector div.foo');
232
+ });
233
+ });
234
+ });
235
+
236
+ });
237
+ });
@@ -0,0 +1,119 @@
1
+ Screw.Unit(function() {
2
+ describe("Print", function() {
3
+ describe('when given undefined', function() {
4
+ it("returns 'undefined'", function() {
5
+ expect($.print(undefined)).to(equal, 'undefined');
6
+ });
7
+ });
8
+
9
+ describe('when given null', function() {
10
+ it("returns 'null'", function() {
11
+ expect($.print(null)).to(equal, 'null');
12
+ });
13
+ });
14
+
15
+ describe('when given a number', function() {
16
+ it("returns the string representation of the number", function() {
17
+ expect($.print(1)).to(equal, '1');
18
+ expect($.print(1.01)).to(equal, '1.01');
19
+ expect($.print(-1)).to(equal, '-1');
20
+ });
21
+ });
22
+
23
+ describe('when given a boolean', function() {
24
+ it("returns the string representation of the boolean", function() {
25
+ expect($.print(true)).to(equal, 'true');
26
+ expect($.print(false)).to(equal, 'false');
27
+ });
28
+ });
29
+
30
+ describe('when given a string', function() {
31
+ it("returns the string, quoted", function() {
32
+ expect($.print('asdf')).to(equal, '"asdf"');
33
+ });
34
+
35
+ describe('when the string is longer than the [max_string] option', function() {
36
+ it("returns the string, truncated", function() {
37
+ expect($.print('asdf', { max_string: 3 })).to(equal, '"asd..."');
38
+ });
39
+ });
40
+
41
+ describe('when the strings has quotes or escaped characters', function() {
42
+ it("returns the string, with quotes and escaped characters escaped", function() {
43
+ expect($.print('as"df')).to(equal, '"as\\"df"');
44
+ expect($.print('as\tdf')).to(equal, '"as\\tdf"');
45
+ });
46
+ });
47
+ });
48
+
49
+ describe('when given a function', function() {
50
+ it("returns the function's signature", function() {
51
+ expect($.print(function() {})).to(equal, 'function ()');
52
+ expect($.print(function foo() {})).to(equal, 'function foo()');
53
+ expect($.print(function foo(bar) {})).to(equal, 'function foo(bar)');
54
+ });
55
+ });
56
+
57
+ describe('when given an element', function() {
58
+ it("returns the string representation of the element", function() {
59
+ expect($.print($('<div>').get(0))).to(equal, '<div>');
60
+ expect($.print($('<div foo="bar">').get(0))).to(equal, '<div>');
61
+ });
62
+ });
63
+
64
+ describe('when given an array', function() {
65
+ it("returns the printed elements, comma separated, encircled by square brackets", function() {
66
+ expect($.print([])).to(equal, '[]');
67
+ expect($.print([1])).to(equal, '[ 1 ]');
68
+ expect($.print([1, 2, 3])).to(equal, '[ 1, 2, 3 ]');
69
+ });
70
+
71
+ describe('when the array is longer than the [max_array] option', function() {
72
+ it("returns the printed array, truncated", function() {
73
+ expect($.print([1, 2, 3, 4], { max_array: 2 })).to(equal, '[ 1, 2, 2 more... ]');
74
+ });
75
+ });
76
+
77
+ describe('when the array has arrays as its elements', function() {
78
+ it("returns the recursively printed array", function() {
79
+ expect($.print([[]])).to(equal, '[ [] ]');
80
+ expect($.print([ [1, 2, 3], 4 ])).to(equal, '[ [ 1, 2, 3 ], 4 ]');
81
+ });
82
+ });
83
+
84
+ describe('when the array has objects as its elements', function() {
85
+ it("returns recursively printed array", function() {
86
+ expect($.print([{}])).to(equal, '[ {} ]');
87
+ expect($.print([ { foo: 'bar' }, 'baz' ])).to(equal, '[ { foo: "bar" }, "baz" ]');
88
+ });
89
+ });
90
+ });
91
+
92
+ describe('when given a jQuery', function() {
93
+ it("returns the printed array of elements engirthed in '$()' ", function() {
94
+ expect($.print($('<div>'))).to(equal, '$([ <div> ])');
95
+ });
96
+ });
97
+
98
+ describe('when given an object', function() {
99
+ it("returns the keys and values of the object, enraptured with curly braces", function() {
100
+ expect($.print({})).to(equal, '{}');
101
+ expect($.print({ foo: 1, bar: 2 })).to(equal, '{ foo: 1, bar: 2 }');
102
+ });
103
+
104
+ describe('when the values of the object are non-primitive', function() {
105
+ it("recursively prints the keys and values", function() {
106
+ expect($.print({ foo: [1, 2] })).to(equal, '{ foo: [ 1, 2 ] }');
107
+ });
108
+
109
+ describe('when the object has circular references', function() {
110
+ it("returns elipses for circularities", function() {
111
+ var circular = {};
112
+ circular[0] = circular;
113
+ expect($.print(circular)).to(equal, '{ 0: { 0: ... } }');
114
+ });
115
+ });
116
+ });
117
+ });
118
+ });
119
+ });
@@ -0,0 +1,18 @@
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
+ <script src="spec_helper.js"></script>
11
+ <script src="behaviors_spec.js"></script>
12
+ <script src="matchers_spec.js"></script>
13
+ <script src="print_spec.js"></script>
14
+
15
+ <link rel="stylesheet" href="../lib/screw.css">
16
+ </head>
17
+ <body></body>
18
+ </html>