jazrb
Jazrb provides support for running JavaScript specs written using the Jasmine JavaScript BDD framework under env.js. It includes support for running via watchr and autotest.
Discussion at groups.google.com/group/jazrb.
Install
You can install the gem via gem install smparkes-jazrb
. If you want to install from github (github.com/smparkes/jazrb), you’ll need to checkout the Jasmine submodule (git submodule update --init
) and also need to make sure you have the prerequisites listed in the gemspec in the Rakefile. rake gemspec
will then build and copy the necessary parts of Jasmine.
If you want to run the examples/tests, you’ll need jQuery. The git submodule update --init
command will have brought in jQuery, but you’ll need to build it: cd vendor/jquery && make
.
Even if you install the gem, you may want to get the github files to see and run the examples.
Use
From the root of a project, i.e., the parent of the spec
directory, you can use the jazrb
command as you would the rspec spec
command, e.g.,
jazrb spec/foo_spec.js spec/bar_spec.js
You can also execute HTML specs via jazrb:
jazrb spec/foo_spec.html
or even normal pages, that have the proper hooks to run as examples (see below).
HTML files must be valid XML, i.e., XHTML, at this time.
The HTML fixture must load the necessary test files. Any number of fixtures can be passed to the jazrb
command.
jazrb uses env.js to run the tests, feeding it your HTML and JavaScript, plus the necessary JavaScript and controls to make the tests run correctly. You can see the entire envjsrb
command by passing jazrb
the -v
flag.
The Jasmine tests are configured to report results in streaming XML (JUnit format, more or less), which jazrb
turns into the familiar rspec format. The --xml
flag causes jazrb
to display the raw XML output.
To run all the tests in the spec
directory repeatedly you can use watchr:
rake test
or
watchr jazrb.watchr
or even
./jazrb.watchr
See jazrb’s own jazrb.watchr
file and the discussion on examples below.
You can also try using autojaz
as you would use autospec
:
autojaz
You’ll need to install the ZenTest gem if you don’t have it installed; jazrb
can be used without ZenTest installed, but autojaz
cannot be. Note that autojaz
may be deprecated in favor of watchr
.
Screen shot at www.scrnshots.com/users/smparkes/screenshots/206033
Examples
There are examples in examples/*
and spec/examples/*
. You can run the tests with rake test
which will run the watchr control file, jazrb.watchr
. (Watchr as a runner will probably replace autojaz.) You’ll need the smparkes-watchr gem.
Running jazrb.watchr
(either with watchr jazrb.watchr
or as ./jazrb.watchr
will run all the tests and then watch the file system for changes. When it sees a change, it reruns the test. It knows how to find the HTML fixtures for specs where they exist in the right place, or it just runs the JavaScript spec itself. An example of the former is the pair example/hello_world.html
and spec/example/hello_world_spec.js
: jazrb will reload the HTML if either file is changed. An example of the latter is spec/example/plain_spec.js
.
You can also load the individual HTML files in the browser to run the tests there. For example, on a Mac, open example/hello_world.html
. (The idea is that for production, the spec helper files are changed to not load the tests: that should be the only change necessary. Or the <script>
tag could be ripped out.) Note that to run the tests from the filesystem in Firefox, you’ll need to set the security.fileuri.strict_origin_policy
option to true.
Recent Changes
-
Pass dependence flag to envjsrb to support watchr dependences
-
Add watchr support
-
Add example
-
Support multiple fixtures on the
jazrb
command. (Actually, this is entirely due toenvjsrb
supporting multiple fixtures. You need a recent build from github or an smparkes-envjs gem version of at least 0.0.5.)
Things to do
-
Complete and test support for loading against an HTTP server.
-
Focus on failing tests until fixed, a la autotest.
-
Extend to more frameworks, e.g., qunit. There’s little here that’s actually Jasmine-specific.
-
Including a missing script should be an error
-
Make work in interactive mode (requires intro/outro/out:blank intergration with envjsrb)
Copyright
Copyright © 2009 Steven Parkes. See LICENSE for details.