screw-unit 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. data/CHANGES +11 -0
  2. data/README.markdown +354 -0
  3. data/Rakefile +40 -0
  4. data/bin/screw_unit +6 -0
  5. data/bin/screw_unit_server +10 -0
  6. data/core/EXAMPLE.html +68 -0
  7. data/core/LICENSE +22 -0
  8. data/core/README.markdown +307 -0
  9. data/core/example/models/cat.js +5 -0
  10. data/core/example/models/man.js +17 -0
  11. data/core/example/spec/matchers/have.js +8 -0
  12. data/core/example/spec/models/cat_spec.js +31 -0
  13. data/core/example/spec/models/man_spec.js +34 -0
  14. data/core/example/spec/spec_helper.js +5 -0
  15. data/core/example/spec/suite.html +25 -0
  16. data/core/lib/jquery-1.2.6.js +3549 -0
  17. data/core/lib/jquery.fn.js +29 -0
  18. data/core/lib/jquery.print.js +109 -0
  19. data/core/lib/screw.assets.js +36 -0
  20. data/core/lib/screw.behaviors.js +91 -0
  21. data/core/lib/screw.builder.js +80 -0
  22. data/core/lib/screw.css +90 -0
  23. data/core/lib/screw.events.js +44 -0
  24. data/core/lib/screw.matchers.js +145 -0
  25. data/core/lib/screw.server.js +21 -0
  26. data/core/spec/behaviors_spec.js +178 -0
  27. data/core/spec/matchers_spec.js +237 -0
  28. data/core/spec/print_spec.js +152 -0
  29. data/core/spec/spec_helper.js +0 -0
  30. data/core/spec/suite.html +18 -0
  31. data/init.rb +0 -0
  32. data/lib/screw_unit.rb +26 -0
  33. data/lib/screw_unit/resources.rb +2 -0
  34. data/lib/screw_unit/resources/spec.rb +38 -0
  35. data/spec/functional/functional_spec.rb +25 -0
  36. data/spec/functional/functional_spec_helper.rb +55 -0
  37. data/spec/functional_suite.rb +10 -0
  38. data/spec/spec_suite.rb +3 -0
  39. data/spec/unit/js_test_core/specs/spec_dir_spec.rb +39 -0
  40. data/spec/unit/js_test_core/specs/spec_file_spec.rb +35 -0
  41. data/spec/unit/unit_spec_helper.rb +120 -0
  42. data/spec/unit_suite.rb +10 -0
  43. data/vendor/js-test-core/CHANGES +15 -0
  44. data/vendor/js-test-core/README +12 -0
  45. data/vendor/js-test-core/Rakefile +72 -0
  46. data/vendor/js-test-core/lib/js_test_core.rb +38 -0
  47. data/vendor/js-test-core/lib/js_test_core/client.rb +114 -0
  48. data/vendor/js-test-core/lib/js_test_core/extensions.rb +3 -0
  49. data/vendor/js-test-core/lib/js_test_core/extensions/time.rb +6 -0
  50. data/vendor/js-test-core/lib/js_test_core/rack.rb +2 -0
  51. data/vendor/js-test-core/lib/js_test_core/rack/commonlogger.rb +5 -0
  52. data/vendor/js-test-core/lib/js_test_core/rails_server.rb +22 -0
  53. data/vendor/js-test-core/lib/js_test_core/resources.rb +10 -0
  54. data/vendor/js-test-core/lib/js_test_core/resources/dir.rb +67 -0
  55. data/vendor/js-test-core/lib/js_test_core/resources/file.rb +49 -0
  56. data/vendor/js-test-core/lib/js_test_core/resources/file_not_found.rb +11 -0
  57. data/vendor/js-test-core/lib/js_test_core/resources/runner.rb +105 -0
  58. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_dir.rb +46 -0
  59. data/vendor/js-test-core/lib/js_test_core/resources/specs/spec_file.rb +17 -0
  60. data/vendor/js-test-core/lib/js_test_core/resources/suite.rb +40 -0
  61. data/vendor/js-test-core/lib/js_test_core/resources/suite_finish.rb +17 -0
  62. data/vendor/js-test-core/lib/js_test_core/resources/web_root.rb +63 -0
  63. data/vendor/js-test-core/lib/js_test_core/selenium.rb +2 -0
  64. data/vendor/js-test-core/lib/js_test_core/selenium/selenium_driver.rb +5 -0
  65. data/vendor/js-test-core/lib/js_test_core/selenium_server_configuration.rb +48 -0
  66. data/vendor/js-test-core/lib/js_test_core/server.rb +50 -0
  67. data/vendor/js-test-core/lib/js_test_core/thin.rb +3 -0
  68. data/vendor/js-test-core/lib/js_test_core/thin/backends/js_test_core_server.rb +9 -0
  69. data/vendor/js-test-core/lib/js_test_core/thin/js_test_core_connection.rb +8 -0
  70. data/vendor/js-test-core/spec/example_core/JsTestCore.css +0 -0
  71. data/vendor/js-test-core/spec/example_core/JsTestCore.js +0 -0
  72. data/vendor/js-test-core/spec/example_public/favicon.ico +0 -0
  73. data/vendor/js-test-core/spec/example_public/javascripts/foo.js +3 -0
  74. data/vendor/js-test-core/spec/example_public/javascripts/large_file.js +59 -0
  75. data/vendor/js-test-core/spec/example_public/javascripts/subdir/bar.js +1 -0
  76. data/vendor/js-test-core/spec/example_public/robots.txt +0 -0
  77. data/vendor/js-test-core/spec/example_public/stylesheets/example.css +3 -0
  78. data/vendor/js-test-core/spec/example_specs/failing_spec.js +5 -0
  79. data/vendor/js-test-core/spec/example_specs/foo/failing_spec.js +6 -0
  80. data/vendor/js-test-core/spec/example_specs/foo/passing_spec.js +6 -0
  81. data/vendor/js-test-core/spec/spec_suite.rb +2 -0
  82. data/vendor/js-test-core/spec/specs/failing_spec.js +0 -0
  83. data/vendor/js-test-core/spec/unit/js_test_core/client_spec.rb +166 -0
  84. data/vendor/js-test-core/spec/unit/js_test_core/rails_server_spec.rb +45 -0
  85. data/vendor/js-test-core/spec/unit/js_test_core/resources/dir_spec.rb +52 -0
  86. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_not_found_spec.rb +16 -0
  87. data/vendor/js-test-core/spec/unit/js_test_core/resources/file_spec.rb +128 -0
  88. data/vendor/js-test-core/spec/unit/js_test_core/resources/runners/runner_spec.rb +283 -0
  89. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_dir_spec.rb +105 -0
  90. data/vendor/js-test-core/spec/unit/js_test_core/resources/specs/spec_file_spec.rb +42 -0
  91. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_finish_spec.rb +82 -0
  92. data/vendor/js-test-core/spec/unit/js_test_core/resources/suite_spec.rb +86 -0
  93. data/vendor/js-test-core/spec/unit/js_test_core/resources/web_root_spec.rb +32 -0
  94. data/vendor/js-test-core/spec/unit/js_test_core/selenium_server_configuration_spec.rb +49 -0
  95. data/vendor/js-test-core/spec/unit/js_test_core/server_spec.rb +117 -0
  96. data/vendor/js-test-core/spec/unit/thin/js_test_core_connection_spec.rb +6 -0
  97. data/vendor/js-test-core/spec/unit/unit_spec_helper.rb +134 -0
  98. data/vendor/js-test-core/spec/unit_suite.rb +10 -0
  99. data/vendor/js-test-core/vendor/thin-rest/CHANGES +2 -0
  100. data/vendor/js-test-core/vendor/thin-rest/README +0 -0
  101. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest.rb +9 -0
  102. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/connection.rb +116 -0
  103. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions.rb +3 -0
  104. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/extensions/object.rb +21 -0
  105. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource.rb +104 -0
  106. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/resource_invalid.rb +4 -0
  107. data/vendor/js-test-core/vendor/thin-rest/lib/thin_rest/routing_error.rb +5 -0
  108. data/vendor/js-test-core/vendor/thin-rest/spec/spec_suite.rb +5 -0
  109. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/connection_spec.rb +207 -0
  110. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest/resource_spec.rb +127 -0
  111. data/vendor/js-test-core/vendor/thin-rest/spec/thin_rest_spec_helper.rb +124 -0
  112. metadata +210 -0
@@ -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">')
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.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>