btakita-screw-unit-server 0.3.0

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