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
data/CHANGES ADDED
@@ -0,0 +1,11 @@
1
+ 0.3.1
2
+ - Client accepts selenium_server_start_command parameter, which allows the user to parameterize the selenium_server_start_command
3
+ - Added support for running specs in Internet Explorer via POST /runners/iexplore
4
+ - Resource file download performance improvements via caching and chunked sending
5
+ - Fixed false positive bug when Client connection times out
6
+
7
+ 0.3.0
8
+ - Uses ScrewUnit 0.3.0
9
+
10
+ 0.1.0
11
+ - Initial Release
@@ -0,0 +1,354 @@
1
+ # Screw Unit Server
2
+ The Screw Unit ruby library is a server runner for the Screw Unit javascript library.
3
+
4
+ # Installing Screw Unit
5
+ You can use Screw Unit as a gem or as a Rails plugin.
6
+ To install the gem, run:
7
+ sudo gem install screw_unit
8
+
9
+ To install the plugin with Rails 2.1.0:
10
+ script/plugin install git://github.com/pivotal/screw-unit-server.git
11
+
12
+ To install the plugin with Rails <2.1.0:
13
+ cd vendor/plugins
14
+ git clone git://github.com/pivotal/screw-unit-server.git
15
+
16
+ After installing screw unit server, run:
17
+ script/generate screw_unit
18
+
19
+ The Rails plugin gives you generators when using Screw Unit in a Rails environment.
20
+
21
+ # Running Screw Unit Server
22
+ First you need to start your Screw Unit server.
23
+
24
+ If you are using screw_unit_server as a Rails plugin, you can simply run:
25
+ script/screw_unit_server
26
+
27
+ If you are using the screw_unit gem, you can run:
28
+ screw_unit_server /path/to/your/javascript/spec/files /path/to/your/javascript/implementation/files
29
+
30
+ Once the server is started, there are two possibly ways to run your js spec:
31
+ * Open your browser to http://localhost:8080/specs
32
+ * Start the Selenium server by running `selenium` from the command line, then running `screw_unit` from the command line
33
+
34
+ # Screw Unit on CI
35
+ JS spec uses the Selenium gem to automatically control browsers on different machines.
36
+
37
+ To use Screw Unit in a CI environment,
38
+ * Install and run the selenium RC server on the machine that you want to run the browsers by using the command:
39
+ selenium
40
+ * Run the screw_unit_server on the machine that has the files.
41
+ script/screw_unit_server
42
+ * Run the screw_unit client. The screw_unit client has --selenium_browser_start_command, --selenium_host, --selenium_port, and --spec_url arguments to specify
43
+ where the Selenium server is relative to the screw_unit server, and where the screw_unit server is relative to the browser.
44
+ * Running `script/screw_unit_server` is equivalent to running `script/screw_unit_server --selenium_browser_start_command *firefox --selenium_host localhost --selenium_port 4444 --spec_url http://localhost:8080/specs`
45
+
46
+ # Screw Unit Library
47
+
48
+ Screw.Unit is a Behavior-Driven Testing Framework for Javascript. It features nested describes. Its goals are to provide:
49
+
50
+ * a DSL for elegant, readable, organized specs;
51
+ * an interactive runner that can execute focused specs and describes;
52
+ * and brief, extensible source-code.
53
+
54
+ # What it is
55
+
56
+ ![Test Runner](http://s3.amazonaws.com/assets.pivotallabs.com/87/original/runner.png)
57
+
58
+ The testing language is closure-based. Consider,
59
+
60
+ describe("Matchers", function() {
61
+ it("invokes the provided matcher on a call to expect", function() {
62
+ expect(true).to(equal, true);
63
+ expect(true).to_not(equal, false);
64
+ });
65
+ });
66
+
67
+ A key feature of Screw.Unit are nested `describes` and the cascading `before` (and `after`) behavior that entails:
68
+
69
+ describe("a nested describe", function() {
70
+ var invocations = [];
71
+
72
+ before(function() {
73
+ invocations.push("before");
74
+ });
75
+
76
+ describe("a doubly nested describe", function() {
77
+ before(function() {
78
+ invocations.push('inner before');
79
+ });
80
+
81
+ it("runs befores in all ancestors prior to an it", function() {
82
+ expect(invocations).to(equal, ["before", "inner before"]);
83
+ });
84
+ });
85
+ });
86
+
87
+ # The Runner
88
+
89
+ The Screw.Unit runner is pretty fancy, supporting focused `describes` and focused `its`:
90
+
91
+ ![Focused Runner](http://s3.amazonaws.com/assets.pivotallabs.com/86/original/focused.png)
92
+
93
+ Click on a `describe` or `it` to run just those tests.
94
+
95
+ # Global Befores and Afters
96
+
97
+ 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.
98
+
99
+ Screw.Unit(function() {
100
+ before(function() { ... });
101
+ });
102
+
103
+ Note that you can have any number of `Screw.Unit(...)` blocks in one file. Thus, you can have multiple global `befores` and `afters`.
104
+
105
+ # Custom Matchers
106
+
107
+ 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:
108
+
109
+ Screw.Matchers["be_even"] = {
110
+ match: function(expected, actual) {
111
+ return actual % 2 == 0;
112
+ },
113
+ failure_message: function(expected, actual, not) {
114
+ return 'expected ' + $.print(actual) + (not ? ' not' : '') + ' to be even';
115
+ }
116
+ }
117
+
118
+ You can invoke this matcher as follows: `expect(2).to(be_even)`.
119
+
120
+ # The Anatomy of Test Infrastructure
121
+
122
+ Typical test infrastructure spans multiple files:
123
+
124
+ * 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.
125
+ * A `spec_helper.js` file with global `before` and `after` blocks.
126
+ * A set of custom matchers.
127
+ * Your individual tests.
128
+
129
+ The file structure will typically look like:
130
+
131
+ spec/
132
+ suite.html
133
+ spec_helper.js
134
+ matchers/
135
+ a_matcher.js
136
+ another_matcher.js
137
+ models/
138
+ a_spec.js
139
+ another_spec.js
140
+ views/
141
+ yet_another_spec.js
142
+
143
+ 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.
144
+
145
+ # Writing Good Tests
146
+
147
+ A great test maximizes these features:
148
+
149
+ * it provides **documentation**, explaining the intended functioning of the system as well as how the source code works;
150
+ * it supports **ongoing development**, as you bit-by-bit write a failing test and make it pass;
151
+ * it supports **refactoring** and **prevents regression**;
152
+ * and it **requires little modification** as the implementation of the system changes, especially changes to unrelated code.
153
+
154
+ 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 it.
155
+
156
+ ## Use Nested Describes to Express Context
157
+
158
+ 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.
159
+
160
+ describe("Caller#prioritize", function() {
161
+ describe("when there are two callers in the queue", function() {
162
+ describe("and one caller has been waiting longer than another", function() {
163
+ ...
164
+ });
165
+ });
166
+ });
167
+
168
+ 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.
169
+
170
+ describe("Car", function() {
171
+ describe("#start", function() {
172
+ });
173
+
174
+ describe("#stop", function() {
175
+ });
176
+
177
+ describe("callbacks", function() {
178
+ describe("after_purchase", function() {
179
+ });
180
+ });
181
+
182
+ describe("logging", function() {
183
+ });
184
+ });
185
+
186
+ 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.
187
+
188
+ # Test Size
189
+
190
+ Individual tests should be short and sweet. It is sometimes recommended to make only one assertion per test:
191
+
192
+ it("chooses the caller who has been waiting the longest", function() {
193
+ expect(Caller.prioritize()).to(equal, caller_waiting_the_longest);
194
+ });
195
+
196
+ 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.
197
+
198
+ 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:
199
+
200
+ it("returns the string representation of the boolean", function() {
201
+ expect($.print(true)).to(equal, 'true');
202
+ expect($.print(false)).to(equal, 'false');
203
+ });
204
+
205
+ Two tests would be overkill in this example.
206
+
207
+ ## Variable Naming
208
+
209
+ Name variables descriptively, especially ones that will become expected values in assertions. `caller_waiting_the_longest` is better than `c1`.
210
+
211
+ ## Dividing code between tests and `befores`
212
+
213
+ 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:
214
+
215
+ it("decrements the man's luck by 5", function() {
216
+ var man = new Man({luck: 5});
217
+
218
+ cat.cross_path(man);
219
+ expect(man.luck()).to(equal, 0);
220
+ });
221
+
222
+ But in general, it's nice to keep setup code in `before` blocks, especially if the setup can be shared across tests.
223
+
224
+ describe('Man', function() {
225
+ var man;
226
+ before(function() {
227
+ man = new Man({luck: 5});
228
+ });
229
+
230
+ describe('#decrement_luck', function() {
231
+ it("decrements the luck field by the given amount", function() {
232
+ man.decrement_luck(3);
233
+ expect(man.luck()).to(equal, 2)
234
+ });
235
+ });
236
+ ...
237
+ });
238
+
239
+ ## Preconditions
240
+
241
+ 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:
242
+
243
+ it("decrements the luck field by the given amount", function() {
244
+ expect(man.luck()).to(equal, 5);
245
+
246
+ man.decrement_luck(3);
247
+ expect(man.luck()).to(equal, 2)
248
+ });
249
+
250
+ 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.
251
+
252
+ ## Behavioral Testing
253
+
254
+ 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.
255
+
256
+ it("invokes #decrement_luck", function() {
257
+ var decrement_luck_was_called = false;
258
+ man.decrement_luck = function(amount) {
259
+ decrement_luck_was_called = true;
260
+ });
261
+
262
+ cat.cross_path(man);
263
+ expect(decrement_luck_was_called).to(equal, true);
264
+ });
265
+
266
+ # How to Test the DOM
267
+
268
+ 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.
269
+
270
+ In `suite.html`:
271
+
272
+ <div id="dom_test"></div>
273
+
274
+ In `spec_helper.js`:
275
+
276
+ Screw.Unit(function() {
277
+ before(function() {
278
+ document.getElementById('dom_test').innerHTML = ''; // but use your favorite JS library here.
279
+ });
280
+ });
281
+
282
+ In `some_spec.js`:
283
+
284
+ describe("something that manipulates the DOM", function() {
285
+ it("is effortless to test!", function() {
286
+ var dom_test = document.getElementById('dom_test');
287
+ dom_test.innerHTML = 'awesome';
288
+ expect(dom_test.innerHTML).to(equal, 'awesome');
289
+ });
290
+ });
291
+
292
+ A Javascript library like jQuery, Prototype, or YUI is a essential for testing events.
293
+
294
+ # Implementation Details
295
+
296
+ 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:
297
+
298
+ var contents = fn.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1];
299
+ var fn = new Function("matchers", "specifications",
300
+ "with (specifications) { with (matchers) { " + contents + " } }"
301
+ );
302
+
303
+ fn.call(this, Screw.Matchers, Screw.Specifications);
304
+
305
+ 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,
306
+
307
+ $('.describe').fn({
308
+ parent: function() {
309
+ return $(this).parent('.describes').parent('.describe');
310
+ },
311
+ run: function() {
312
+ $(this).children('.its').children('.it').fn('run');
313
+ $(this).children('.describes').children('.describe').fn('run');
314
+ },
315
+ });
316
+
317
+ Here two methods (`#parent` and `#run`) are attached directly to DOM elements that have class `describe`. To invoke one of these methods, simply:
318
+
319
+ $('.describe').fn('run');
320
+
321
+ 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:
322
+
323
+ $('.describe, .it').fn({...}); // applies to both describe and its
324
+ $('.describe .describe').fn({...}); // applies to nested describes only
325
+
326
+ # Extensibility
327
+
328
+ Screw.Unit is designed from the ground-up to be extensible. For example, to add custom logging, simply subscribe to certain events:
329
+
330
+ $('.it')
331
+ .bind('enqueued', function() {...})
332
+ .bind('running', function() {...})
333
+ .bind('passed', function() {...})
334
+ .bind('failed', function(e, reason) {...})
335
+
336
+ There are also events for the `loading` and `loaded` test code code, as well as just `before` and just `after` all tests are run:
337
+
338
+ $(Screw)
339
+ .bind('loading', function() {...})
340
+ .bind('loaded', function() {...})
341
+ .bind('before', function() {...})
342
+ .bind('after', function() {...})
343
+
344
+ # Download
345
+
346
+ You can [download the source](http://github.com/nkallen/screw-unit/tree/master) from Github. There is are plenty of examples in the distribution.
347
+
348
+ # Thanks to
349
+
350
+ * Nathan Sobo
351
+ * Yehuda Katz
352
+ * Brian Takita
353
+ * Aman Gupta
354
+ * Tim Connor
@@ -0,0 +1,40 @@
1
+ require "rake"
2
+ require 'rake/gempackagetask'
3
+ require 'rake/contrib/rubyforgepublisher'
4
+ require 'rake/clean'
5
+ require 'rake/testtask'
6
+ require 'rake/rdoctask'
7
+
8
+ desc "Runs the Rspec suite"
9
+ task(:default) do
10
+ run_suite
11
+ end
12
+
13
+ desc "Runs the Rspec suite"
14
+ task(:spec) do
15
+ run_suite
16
+ end
17
+
18
+ desc "Copies the trunk to a tag with the name of the current release"
19
+ task(:tag_release) do
20
+ tag_release
21
+ end
22
+
23
+ def run_suite
24
+ dir = File.dirname(__FILE__)
25
+ system("ruby #{dir}/spec/spec_suite.rb") || raise("Example Suite failed")
26
+ end
27
+
28
+ spec = eval(File.read("#{File.dirname(__FILE__)}/screw-unit-server.gemspec"))
29
+ PKG_NAME = spec.name
30
+ PKG_VERSION = spec.version
31
+
32
+ Rake::GemPackageTask.new(spec) do |pkg|
33
+ pkg.need_zip = true
34
+ pkg.need_tar = true
35
+ end
36
+
37
+ def tag_release
38
+ dashed_version = PKG_VERSION.gsub('.', '-')
39
+ system("git tag REL-#{dashed_version} -m 'Version #{PKG_VERSION}'")
40
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift("#{dir}/../lib")
5
+ require "screw_unit"
6
+ exit ScrewUnit::Client.run_argv(ARGV)
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ dir = File.dirname(__FILE__)
4
+ $LOAD_PATH.unshift("#{dir}/../lib")
5
+ require "screw_unit"
6
+
7
+ spec_root_path = ARGV[0] || raise("You need to pass in a spec root")
8
+ implementation_root_path = ARGV[1] || raise("You need to pass in an implementation root")
9
+ public_path = ARGV[2] || raise("You need to pass in a public path")
10
+ ScrewUnit::Server.run(spec_root_path, implementation_root_path, public_path)
@@ -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>