Tired of waiting 10 seconds before your tests run? RailsTestServing can make them run almost instantly.
-
Install the gem:
gem install Roman2K-rails-test-serving -v '>= 0.1.2' -s http://gems.github.com
-
Insert the following lines at the very top of
test/test_helper.rb
:require 'rubygems' require 'rails_test_serving' RailsTestServing.boot
-
Append the following line to
~/.bash_profile
:export RUBYLIB=".:test:$RUBYLIB"
If you get loading errors during the next steps:
-
Move the
RUBYLIB
line from~/.bash_profile
to~/.bash_login
instead. -
If you are using TextMate, you may try to apply this (hopefully temporary) fix.
-
-
Start the server:
cd <project-dir> ruby test/test_helper.rb --serve
-
Run tests as you usually do:
ruby test/unit/account_test.rb ruby test/unit/account_test.rb -n /balance/
As a consequence, they work in RubyMate too (⌘R in TextMate).
-
Details in the introduction article.
Note: if the server is not started, tests fall back to running the usual way.
An option hash can be specified for RailsTestServing to use, by defining $test_server_options
right before require 'rails_test_serving'
. It must be a hash with symbol keys. Currently available options are:
reload
-
An array of regular expressions (or any object responding to
#===
) matching the name of the files that should be forced to reload right after the regular constant cleanup. Note that the constants these files have defined are not removed before the newrequire
.
Example test_helper.rb
head:
require 'rubygems' $test_server_options = { :reload => [/blueprint/] } require 'rails_test_serving' RailsTestServing.boot # ...remainder here...
-
Tested working with Rails 2.1.2 up to 2.2.0 RC2. Compatibility with versions of Rails out of that range is guaranteed.
-
There might exist some quirks: search for “TODO” in the source. I can bear them but contributions are welcome.
-
Some unit tests are left to be written.
Code:
-
Roman Le Négrate, a.k.a. Roman2K (contact)
-
Jack Chen, a.k.a. chendo
Feedback:
-
Justin Ko
Released under the MIT license: see the LICENSE
file.