JSpec-Rails - Rails integration for JSpec
Jspec-rails has the following features:
detects file changes and refreshes the browser to cause the specifications to run again - for example you can have Safari, Firefox and IE open and all will rerun the tests when a file is changed
uses a rails controller to deliver spec files and fixtures
you can use erb, haml, builder etc. in your fixtures
you can use erb in your specs
Install the plugin:
./script/plugin install git://github.com/bhauman/jspec-rails.git
Initialize your app:
Now start or restart your app and navigate to it the jspec controller. For example if you are running webrick on port 3000 navigate to:
You should see the self tests for the jspec_rails.js library run (and pass).
./script/generate jspec_library widgeteer
This will create the following files:
This command also adds a line to jspec/jspec.yml under required_libs:
required_libs: - prototype - effects - widgeteer // this line was added
Now you can edit the jspec/spec/widgeteer_spec.js and add some specifications for it. Note that each time you save the file it will refresh and run the specs in the browser (the browser needs to be open first).
Please refer to the JSpec documentation at:
When you load another fixture the previous one will be replaced. But if you want to explicitly unload the current fixture do this:
Fixtures are loaded into the play area.
The play_area is a hidden dom element where fixtures are loaded into. The current thinking is that it holds one fixture at a time and its contents are replaced by the next fixture loaded.
You can access elements in your fixture through the play_area using the Prototype.js select() method
The jspec-rails configuration file can be found at jspec/jspec.yml. The generated config should look something like this:
The watched_dirs section is a list of directories that are watched for changes. The directories are all relative to Rails.root
The authorization section has no effect on the behavior of the plugin as of yet.
As of now this plugin is implemented as an Engine and so requires Rails 2.3. That being said the jspec_controller.rb file in the app directory of the plugin is probably the only file that requires Engine functionality to be found. There are various ways to work around this.
This plugin can easily be extended to work with the Scriptaculous testing framework.
(The MIT License)
Copyright © 2009 Bruce Hauman <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright © 2009 Bruce Hauman, released under the MIT license