| 1 |
=JavaScript testing plugin |
|---|
| 2 |
|
|---|
| 3 |
This plugin provides the script.aculo.us JavaScript unit testing framework |
|---|
| 4 |
in a way that integrates with Rails applications. |
|---|
| 5 |
|
|---|
| 6 |
==Usage |
|---|
| 7 |
|
|---|
| 8 |
Use the provided generator to built a skeleton for your JavaScript test. |
|---|
| 9 |
The built-in rake task can then be used to automatically run the unit tests |
|---|
| 10 |
in various installed browsers (supported are Firefox on IE/Mac/Linux, |
|---|
| 11 |
Safari on Mac, Konqueror on Linux). |
|---|
| 12 |
|
|---|
| 13 |
Note that due to the built-in webrick, you don't have to change anything |
|---|
| 14 |
about your app, just add tests. :) |
|---|
| 15 |
|
|---|
| 16 |
==Example |
|---|
| 17 |
|
|---|
| 18 |
Generate a JavaScript test skeleton for your public/javascripts/foo.js file: |
|---|
| 19 |
|
|---|
| 20 |
script/generate javascript_test foo |
|---|
| 21 |
|
|---|
| 22 |
Run the unit tests (an "assertTruth" dummy test is provided, |
|---|
| 23 |
so you should see "SUCCESS" messages), and see the automagically |
|---|
| 24 |
controlled browsers in action: |
|---|
| 25 |
|
|---|
| 26 |
rake test:javascripts |
|---|
| 27 |
|
|---|
| 28 |
You have to manually close the browser window(s) afterwards. |
|---|
| 29 |
|
|---|
| 30 |
You can also run the test manually, by symlinking the assets directory. |
|---|
| 31 |
In your Rails application root, run: |
|---|
| 32 |
|
|---|
| 33 |
ln -s ../../vendor/plugins/javascript_test/assets/ test/javascript/assets |
|---|
| 34 |
|
|---|
| 35 |
You then can just open the individual .html test files in your browser. |
|---|
| 36 |
|
|---|
| 37 |
All in all, unittest.js is closely modelled on Test::Unit. You can find lots |
|---|
| 38 |
of examples in both the Prototype and script.aculo.us SVN repositories. |
|---|
| 39 |
|
|---|
| 40 |
You'll find more info on how to write tests on the script.aculo.us wiki: |
|---|
| 41 |
http://wiki.script.aculo.us/scriptaculous/show/UnitTesting. |
|---|
| 42 |
The documentation there is not really complete, so feel free to help out. |
|---|
| 43 |
|
|---|
| 44 |
==Questions? |
|---|
| 45 |
|
|---|
| 46 |
Join the Rails Spinoffs Google Group, or ask on #prototype on irc.freenode.net. |
|---|
| 47 |
|
|---|
| 48 |
==Credits |
|---|
| 49 |
|
|---|
| 50 |
Big thanks with sugar on the top to Jon Tirsen, who authored the automated |
|---|
| 51 |
browser remote control-gadgetry. |
|---|
| 52 |
|
|---|
| 53 |
==TODO |
|---|
| 54 |
|
|---|
| 55 |
* Some more docs and a presentation :) |
|---|
| 56 |
* Make ^C aborting work |
|---|
| 57 |
|
|---|
| 58 |
== License |
|---|
| 59 |
|
|---|
| 60 |
Copyright (c) 2005-2008 Thomas Fuchs, released under the MIT license |
|---|