screw_server 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Gemfile.run +3 -0
  2. data/Gemfile.run.lock +41 -0
  3. data/assets/screw-jslint.js +69 -0
  4. data/assets/screw-server.js +120 -0
  5. data/assets/screw.css +70 -0
  6. data/assets/vendor/fulljslint.js +5699 -0
  7. data/assets/vendor/screw-unit/CHANGES +7 -0
  8. data/assets/vendor/screw-unit/EXAMPLE.html +68 -0
  9. data/assets/vendor/screw-unit/LICENSE +22 -0
  10. data/assets/vendor/screw-unit/README.markdown +307 -0
  11. data/assets/vendor/screw-unit/example/models/cat.js +5 -0
  12. data/assets/vendor/screw-unit/example/models/man.js +17 -0
  13. data/assets/vendor/screw-unit/example/spec/matchers/have.js +8 -0
  14. data/assets/vendor/screw-unit/example/spec/models/cat_spec.js +31 -0
  15. data/assets/vendor/screw-unit/example/spec/models/man_spec.js +34 -0
  16. data/assets/vendor/screw-unit/example/spec/spec_helper.js +5 -0
  17. data/assets/vendor/screw-unit/example/spec/suite.html +25 -0
  18. data/assets/vendor/screw-unit/lib/jquery-1.2.6.js +3549 -0
  19. data/assets/vendor/screw-unit/lib/jquery.fn.js +29 -0
  20. data/assets/vendor/screw-unit/lib/jquery.print.js +109 -0
  21. data/assets/vendor/screw-unit/lib/screw.behaviors.js +101 -0
  22. data/assets/vendor/screw-unit/lib/screw.builder.js +90 -0
  23. data/assets/vendor/screw-unit/lib/screw.css +90 -0
  24. data/assets/vendor/screw-unit/lib/screw.events.js +45 -0
  25. data/assets/vendor/screw-unit/lib/screw.matchers.js +203 -0
  26. data/assets/vendor/screw-unit/spec/behaviors_spec.js +188 -0
  27. data/assets/vendor/screw-unit/spec/matchers_spec.js +391 -0
  28. data/assets/vendor/screw-unit/spec/print_spec.js +158 -0
  29. data/assets/vendor/screw-unit/spec/spec_helper.js +0 -0
  30. data/assets/vendor/screw-unit/spec/suite.html +18 -0
  31. data/assets/vendor/smoke/LICENSE +22 -0
  32. data/assets/vendor/smoke/README.markdown +68 -0
  33. data/assets/vendor/smoke/lib/smoke.core.js +49 -0
  34. data/assets/vendor/smoke/lib/smoke.mock.js +219 -0
  35. data/assets/vendor/smoke/lib/smoke.stub.js +29 -0
  36. data/assets/vendor/smoke/plugins/screw.mocking.js +26 -0
  37. data/assets/vendor/smoke/spec/core_spec.js +115 -0
  38. data/assets/vendor/smoke/spec/mock_spec.js +431 -0
  39. data/assets/vendor/smoke/spec/screw_integration_spec.js +17 -0
  40. data/assets/vendor/smoke/spec/spec_helper.js +0 -0
  41. data/assets/vendor/smoke/spec/stub_spec.js +17 -0
  42. data/assets/vendor/smoke/spec/su/jquery-1.2.3.js +3408 -0
  43. data/assets/vendor/smoke/spec/su/jquery.fn.js +29 -0
  44. data/assets/vendor/smoke/spec/su/jquery.print.js +108 -0
  45. data/assets/vendor/smoke/spec/su/screw.behaviors.js +91 -0
  46. data/assets/vendor/smoke/spec/su/screw.builder.js +80 -0
  47. data/assets/vendor/smoke/spec/su/screw.css +74 -0
  48. data/assets/vendor/smoke/spec/su/screw.events.js +38 -0
  49. data/assets/vendor/smoke/spec/su/screw.matchers.js +65 -0
  50. data/assets/vendor/smoke/spec/suite.html +29 -0
  51. data/bin/screw_server +43 -0
  52. data/lib/screw_server/app.rb +197 -0
  53. data/lib/screw_server/base.rb +21 -0
  54. data/lib/screw_server/fixture_file.rb +17 -0
  55. data/lib/screw_server/jslint_suite.rb +51 -0
  56. data/lib/screw_server/spec_file.rb +76 -0
  57. data/lib/screw_server.rb +2 -0
  58. data/screw_server.gemspec +28 -0
  59. data/views/index.haml +13 -0
  60. data/views/missing_spec_helper.haml +12 -0
  61. data/views/no_specs.haml +11 -0
  62. data/views/run_spec.haml +30 -0
  63. data/views/sample_spec.js +7 -0
  64. data/views/sample_spec_helper.js +2 -0
  65. metadata +257 -0
@@ -0,0 +1,7 @@
1
+ 0.3.2
2
+ - Adding IE support
3
+ - Fix printing of 0 as 'NaN'
4
+
5
+ 0.2.0
6
+ - Added elapsed time information in test suite run.
7
+ - Equal matchers works with complex hash structures
@@ -0,0 +1,68 @@
1
+ <html>
2
+ <!--
3
+ This file is a fully-functioning example test case. Try opening this file in Firefox, Safari,
4
+ or Internet Explorer to see what a running test looks like.
5
+ This file demonstrates the components involved in writing a simple test, such as:
6
+ * The necessary HTML to run a test (with the required <script> and <link rel="stylesheet"> tags),
7
+ * A "custom matcher" (i.e., a custom assertion) to make your tests more readable,
8
+ * And, a simple test with the necessary boiler-plate code to get you up and running.
9
+ Typically, these components are separated out into multiple files. To see what a more typical suite
10
+ of tests look like, look at the larger example in the examples/ directory.
11
+ -->
12
+ <head>
13
+ <!-- These are all of the necessary javascript and css files required to run your tests -->
14
+ <script src="lib/jquery-1.2.6.js"></script>
15
+ <script src="lib/jquery.fn.js"></script>
16
+ <script src="lib/jquery.print.js"></script>
17
+ <script src="lib/screw.builder.js"></script>
18
+ <script src="lib/screw.matchers.js"></script>
19
+ <script src="lib/screw.events.js"></script>
20
+ <script src="lib/screw.behaviors.js"></script>
21
+ <link rel="stylesheet" href="lib/screw.css">
22
+
23
+ <script type="text/javascript">
24
+ // Here is the system under test (SUT)--that is, your application code that you would like
25
+ // to test.
26
+ function foo() {
27
+ return 2;
28
+ }
29
+ </script>
30
+
31
+ <script type="text/javascript">
32
+ // Here is a Custom Matcher. A custom matcher is a custom assertion,
33
+ // tailored to your application; these help to make your tests more readable.
34
+ Screw.Matchers["be_even"] = {
35
+ match: function(expected, actual) {
36
+ return actual % 2 == 0;
37
+ },
38
+ failure_message: function(expected, actual, not) {
39
+ return 'expected ' + $.print(actual) + (not ? ' not' : '') + ' to be even';
40
+ }
41
+ }
42
+ </script>
43
+
44
+ <script type="text/javascript">
45
+ // Here is a sample test. Note that all tests are wrapped in
46
+ // "Screw.Unit(function() { ... })".
47
+ Screw.Unit(function() {
48
+ // Tests are organized into 'describes' and 'its', following the style of RSpec.
49
+ describe("foo", function() {
50
+ it("returns 2", function() {
51
+ // 'equal' is one among many matchers provided with the Screw.Unit distribution. It
52
+ // is smart enough to compare arrays, objects, and primitives.
53
+ expect(foo()).to(equal, 2);
54
+ });
55
+ });
56
+
57
+ describe("numbers", function() {
58
+ // Here is a use of the custom matcher defined above.
59
+ it("either is or is not even", function() {
60
+ expect(2).to(be_even);
61
+ expect(3).to_not(be_even);
62
+ });
63
+ });
64
+ });
65
+ </script>
66
+ </head>
67
+ <body></body>
68
+ </html>
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 Nick Kallen
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,307 @@
1
+ Screw.Unit is a Behavior-Driven Testing Framework for Javascript. It features nested describes. Its goals are to provide:
2
+
3
+ * a DSL for elegant, readable, organized specs;
4
+ * an interactive runner that can execute focused specs and describes;
5
+ * and brief, extensible source-code.
6
+
7
+ # What it is
8
+
9
+ ![Test Runner](http://s3.amazonaws.com/assets.pivotallabs.com/87/original/runner.png)
10
+
11
+ The testing language is closure-based. Consider,
12
+
13
+ describe("Matchers", function() {
14
+ it("invokes the provided matcher on a call to expect", function() {
15
+ expect(true).to(equal, true);
16
+ expect(true).to_not(equal, false);
17
+ });
18
+ });
19
+
20
+ A key feature of Screw.Unit are nested `describes` and the cascading `before` (and `after`) behavior that entails:
21
+
22
+ describe("a nested describe", function() {
23
+ var invocations = [];
24
+
25
+ before(function() {
26
+ invocations.push("before");
27
+ });
28
+
29
+ describe("a doubly nested describe", function() {
30
+ before(function() {
31
+ invocations.push('inner before');
32
+ });
33
+
34
+ it("runs befores in all ancestors prior to an it", function() {
35
+ expect(invocations).to(equal, ["before", "inner before"]);
36
+ });
37
+ });
38
+ });
39
+
40
+ # The Runner
41
+
42
+ The Screw.Unit runner is pretty fancy, supporting focused `describes` and focused `its`:
43
+
44
+ ![Focused Runner](http://s3.amazonaws.com/assets.pivotallabs.com/86/original/focused.png)
45
+
46
+ Click on a `describe` or `it` to run just those tests.
47
+
48
+ # Global Befores and Afters
49
+
50
+ A global `before` is a `before` block run before all tests in a test suite, regardless of their nesting. This is often useful to reset global variables, or blank-out DOM nodes before each test is run. Put this at the top of the your suite file or in your spec helper.
51
+
52
+ Screw.Unit(function() {
53
+ before(function() { ... });
54
+ });
55
+
56
+ Note that you can have any number of `Screw.Unit(...)` blocks in one file. Thus, you can have multiple global `befores` and `afters`.
57
+
58
+ # Custom Matchers
59
+
60
+ A custom matcher is a custom assertion specifically tailored to your application. These are helpful in increasing the readability and declarativity of your tests. To create a custom matcher, fill in the blanks for this code:
61
+
62
+ Screw.Matchers["be_even"] = {
63
+ match: function(expected, actual) {
64
+ return actual % 2 == 0;
65
+ },
66
+ failure_message: function(expected, actual, not) {
67
+ return 'expected ' + $.print(actual) + (not ? ' not' : '') + ' to be even';
68
+ }
69
+ }
70
+
71
+ You can invoke this matcher as follows: `expect(2).to(be_even)`.
72
+
73
+ # The Anatomy of Test Infrastructure
74
+
75
+ Typical test infrastructure spans multiple files:
76
+
77
+ * A `suite.html` file that has the necessary html, script tags, and link tags, to include your source code as well as the test infrastructure.
78
+ * A `spec_helper.js` file with global `before` and `after` blocks.
79
+ * A set of custom matchers.
80
+ * Your individual tests.
81
+
82
+ The file structure will typically look like:
83
+
84
+ spec/
85
+ suite.html
86
+ spec_helper.js
87
+ matchers/
88
+ a_matcher.js
89
+ another_matcher.js
90
+ models/
91
+ a_spec.js
92
+ another_spec.js
93
+ views/
94
+ yet_another_spec.js
95
+
96
+ The `models` and `views` directories are here only for comparison. As a general rule, mirror the file structure of your source code in your spec directory. For example, if you have an MVC application and you organize your source code into `models`, `views`, and `controllers` directories, have parallel directories in your spec/ directory, with tests for your models, views, and controllers in their respective directories.
97
+
98
+ # Writing Good Tests
99
+
100
+ A great test maximizes these features:
101
+
102
+ * it provides **documentation**, explaining the intended functioning of the system as well as how the source code works;
103
+ * it supports **ongoing development**, as you bit-by-bit write a failing test and make it pass;
104
+ * it supports later **refactoring** and **prevents regression** as you add other features;
105
+ * and it **requires little modification** as the implementation of the system changes, especially changes to unrelated code.
106
+
107
+ This section focuses principally on tests as documentation. **To provide documentation, as well as support future modification, a test should be readable and well organized.** Here are some recommendations on how to do just that.
108
+
109
+ ## Use Nested Describes to Express Context
110
+
111
+ Often, when you test a system (a function, an object), it behaves differently in different contexts. Use **nested** describes liberally to express the context under which you make an assertion.
112
+
113
+ describe("Caller#prioritize", function() {
114
+ describe("when there are two callers in the queue", function() {
115
+ describe("and one caller has been waiting longer than another", function() {
116
+ ...
117
+ });
118
+ });
119
+ });
120
+
121
+ In addition to using nested describes to express context, use them to organize tests by the structural properties of your source code and programming language. In Javascript this is typically prototype and function. A parent describe for a prototype contains nested describes for each of its methods. If you have cross-cutting concerns (e.g., related behavior that spans across methods or prototypes), use a describe to group them conceptually.
122
+
123
+ describe("Car", function() {
124
+ describe("#start", function() {
125
+ });
126
+
127
+ describe("#stop", function() {
128
+ });
129
+
130
+ describe("callbacks", function() {
131
+ describe("after_purchase", function() {
132
+ });
133
+ });
134
+
135
+ describe("logging", function() {
136
+ });
137
+ });
138
+
139
+ In this example, one parent `describe` is used for all `Car` behavior. There is a describe for each method. Finally, cross-cutting concerns like callbacks and logging are grouped because of their conceptual affinity.
140
+
141
+ # Test Size
142
+
143
+ Individual tests should be short and sweet. It is sometimes recommended to make only one assertion per test:
144
+
145
+ it("chooses the caller who has been waiting the longest", function() {
146
+ expect(Caller.prioritize()).to(equal, caller_waiting_the_longest);
147
+ });
148
+
149
+ According to some, the ideal test is one line of code. In practice, it may be excessive to divide your tests to be this small. At ten lines of code (or more), a test is difficult to read quickly. Be pragmatic, bearing in mind the aims of testing.
150
+
151
+ Although one assertion per test is a good rule of thumb, feel free to violate the rule if equal clarity and better terseness is achievable:
152
+
153
+ it("returns the string representation of the boolean", function() {
154
+ expect($.print(true)).to(equal, 'true');
155
+ expect($.print(false)).to(equal, 'false');
156
+ });
157
+
158
+ Two tests would be overkill in this example.
159
+
160
+ ## Variable Naming
161
+
162
+ Name variables descriptively, especially ones that will become expected values in assertions. `caller_waiting_the_longest` is better than `c1`.
163
+
164
+ ## Dividing code between tests and `befores`
165
+
166
+ If there is only one line of setup and it is used in only one test, it may be better to include the setup in the test itself:
167
+
168
+ it("decrements the man's luck by 5", function() {
169
+ var man = new Man({luck: 5});
170
+
171
+ cat.cross_path(man);
172
+ expect(man.luck()).to(equal, 0);
173
+ });
174
+
175
+ But in general, it's nice to keep setup code in `before` blocks, especially if the setup can be shared across tests.
176
+
177
+ describe('Man', function() {
178
+ var man;
179
+ before(function() {
180
+ man = new Man({luck: 5});
181
+ });
182
+
183
+ describe('#decrement_luck', function() {
184
+ it("decrements the luck field by the given amount", function() {
185
+ man.decrement_luck(3);
186
+ expect(man.luck()).to(equal, 2)
187
+ });
188
+ });
189
+ ...
190
+ });
191
+
192
+ ## Preconditions
193
+
194
+ It is ideal, if there is any chance that your preconditions are non-obvious, to make precondition asserts in your test. The last example, were it more complicated, might be better written:
195
+
196
+ it("decrements the luck field by the given amount", function() {
197
+ expect(man.luck()).to(equal, 5);
198
+
199
+ man.decrement_luck(3);
200
+ expect(man.luck()).to(equal, 2)
201
+ });
202
+
203
+ Whitespace, as seen here, can be helpful in distinguishing setup and preconditions from the system under test (SUT) and its assertions. It is nice to be consistent in your use of whitespace (e.g., "always follow a group of preconditions by a newline"). But it is better to use whitespace as makes the most sense given the context. As with everything in life, do it consciously and deliberately, but change your mind frequently.
204
+
205
+ ## Behavioral Testing
206
+
207
+ Behavioral testing, that is, asserting that certain functions are called rather than certain values returned, is best done with closures. The dynamic nature of JavaScript makes mocking frameworks mostly unnecessary.
208
+
209
+ it("invokes #decrement_luck", function() {
210
+ var decrement_luck_was_called = false;
211
+ man.decrement_luck = function(amount) {
212
+ decrement_luck_was_called = true;
213
+ });
214
+
215
+ cat.cross_path(man);
216
+ expect(decrement_luck_was_called).to(equal, true);
217
+ });
218
+
219
+ # How to Test the DOM
220
+
221
+ The simplest way to test the DOM is to have a special DOM node in your `suite.html` file. Have all tests insert nodes into this node; have a global `before` reset the node between tests.
222
+
223
+ In `suite.html`:
224
+
225
+ <div id="dom_test"></div>
226
+
227
+ In `spec_helper.js`:
228
+
229
+ Screw.Unit(function() {
230
+ before(function() {
231
+ document.getElementById('dom_test').innerHTML = ''; // but use your favorite JS library here.
232
+ });
233
+ });
234
+
235
+ In `some_spec.js`:
236
+
237
+ describe("something that manipulates the DOM", function() {
238
+ it("is effortless to test!", function() {
239
+ var dom_test = document.getElementById('dom_test');
240
+ dom_test.innerHTML = 'awesome';
241
+ expect(dom_test.innerHTML).to(equal, 'awesome');
242
+ });
243
+ });
244
+
245
+ A Javascript library like jQuery, Prototype, or YUI is a essential for testing events.
246
+
247
+ # Implementation Details
248
+
249
+ Screw.Unit is implemented using some fancy metaprogramming learned from the formidable Yehuda Katz. This allows the `describe` and `it` functions to not pollute the global namespace. Essentially, we take the source code of your test and wrap it in a with block which provides a new scope:
250
+
251
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
252
+ var fn = new Function("matchers", "specifications",
253
+ "with (specifications) { with (matchers) { " + contents + " } }"
254
+ );
255
+
256
+ fn.call(this, Screw.Matchers, Screw.Specifications);
257
+
258
+ Furthermore, Screw.Unit is implemented using the **Concrete Javascript** style, which is made possible by the [Effen plugin](http://github.com/nkallen/effen/tree/master) and jQuery. Concrete Javascript is an alternative to MVC. In Concrete Javascript, DOM objects serve as the model and view simultaneously. The DOM is constructed using semantic (and visual) markup, and behaviors are attached directly to DOM elements. For example,
259
+
260
+ $('.describe').fn({
261
+ parent: function() {
262
+ return $(this).parent('.describes').parent('.describe');
263
+ },
264
+ run: function() {
265
+ $(this).children('.its').children('.it').fn('run');
266
+ $(this).children('.describes').children('.describe').fn('run');
267
+ },
268
+ });
269
+
270
+ Here two methods (`#parent` and `#run`) are attached directly to DOM elements that have class `describe`. To invoke one of these methods, simply:
271
+
272
+ $('.describe').fn('run');
273
+
274
+ Bind behaviors by passing a hash (see the previous example). Using CSS3 selectors and cascading to attach behaviors provides interesting kind of multiple inheritance and polymorphism:
275
+
276
+ $('.describe, .it').fn({...}); // applies to both describe and its
277
+ $('.describe .describe').fn({...}); // applies to nested describes only
278
+
279
+ # Extensibility
280
+
281
+ Screw.Unit is designed from the ground-up to be extensible. For example, to add custom logging, simply subscribe to certain events:
282
+
283
+ $('.it')
284
+ .bind('enqueued', function() {...})
285
+ .bind('running', function() {...})
286
+ .bind('passed', function() {...})
287
+ .bind('failed', function(e, reason) {...})
288
+
289
+ There are also events for the `loading` and `loaded` test code code, as well as just `before` and just `after` all tests are run:
290
+
291
+ $(Screw)
292
+ .bind('loading', function() {...})
293
+ .bind('loaded', function() {...})
294
+ .bind('before', function() {...})
295
+ .bind('after', function() {...})
296
+
297
+ # Download
298
+
299
+ You can [download the source](http://github.com/nkallen/screw-unit/tree/master) from Github. There is are plenty of examples in the distribution.
300
+
301
+ # Thanks to
302
+
303
+ * Nathan Sobo
304
+ * Yehuda Katz
305
+ * Brian Takita
306
+ * Aman Gupta
307
+ * Tim Connor
@@ -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"></ul>')
12
+ .append('<li class="hair"></li>')
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.6.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>