jeremyw / grand_central forked from Roman2K/rails-test-serving

Makes unit tests of a Rails application run instantly

This URL has Read+Write access

jeremyw (author)
Fri Nov 06 07:44:04 -0800 2009
commit  eb9f8605f5bf8b2f9f6289a0ba14290284ddbc3e
tree    bff2c49e268f64eb90fb73be60f845e75cfcdf89
parent  ca5f7c0d0fd78b9ffbbf004fc7fe02c7038421dc
name age message
file .gitignore Mon Nov 17 22:59:49 -0800 2008 ignore manifest [Roman2K]
file LICENSE Sat Jan 24 16:46:35 -0800 2009 unwrapped license paragraphs [Roman2K]
file Manifest Loading commit data...
file README.mdown
file Rakefile
file grand_central.gemspec
directory lib/
directory test/
README.mdown

GrandCentral

Tired of waiting 10 seconds before your tests run? GrandCentral can make them run almost instantly. This library is described more thoroughly in its introduction article.

Usage

  1. Install the gem:

    gem install grand_central
    
  2. Insert the following lines at the very top of test/test_helper.rb:

    require 'rubygems'
    require 'grand_central'
    GrandCentral.boot
    
  3. 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, add the following line to the top of test_helper.rb:

          $:.reject! { |e| e.include? 'TextMate' }
      
  4. Start the server:

    cd <project-dir>
    ruby test/test_helper.rb --serve
    
  5. 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).
  6. Have a lot a models and/or mixins? You can reduce reloading time to almost nothing by using GrandCentral in combination with RailsDevelopmentBoost. Since was originally intended to speed up web-browsing in development mode, be sure to read the note in the README for how to enable it in test mode.

Note: if the server is not started, tests fall back to running the usual way.

Options

An option hash can be specified for GrandCentral to use, by defining $test_server_options right before require 'grand_central'. 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 kept around before being re-require'd.

Example test_helper.rb head:

require 'rubygems'

$test_server_options = { :reload => [/blueprint/] }
require 'grand_central'
GrandCentral.boot

# ...remainder here...

When running tests from the command line, you can bypass the server, forcing tests to be run locally, by passing the --local flag. For example:

ruby test/unit/account_test.rb --local

Caveats

  • Tested working with Rails 2.1.2 up to 2.2.2. Compatibility with versions of Rails out of that range is not 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.

Credits

Code:

Feedback:

Released under the MIT license: see the LICENSE file.