The purpose of Rails2Preload is to optimize testing with Spin and Rails 2. It does this by splitting the Rails 2 initialization method (Rails::Initializer#process
) into two phases: preload and postload. This gives us the capability of using Spin:
- without having to reboot Rails every time a class is modified
- without having to disable class caching
-
Install the gem:
$ gem install rails_2_preload --version 0.2
-
In your
.spin.rb
file, add:require "rails_2_preload" require "rails_2_preload/spin" Rails2Preload::Spin.add_spin_hooks
-
Start the Spin server
$ spin serve --preload=config/environment.rb --load-path=test
-
Push a test to Spin
$ spin push test/unit/your_test.rb
By default, Rails2Preload preloads until the application classes (i.e. models) are loaded. This is optimal for unit testing. This can be changed, however, with the preload_until
method. For example, for functional tests, we may want to preload everything up until the views:
Rails2Preload.preload_until(:load_view_paths)
To take advantage of this feature, create a Ruby script and preload it with Spin (instead of config/environment.rb
):
$ spin serve --preload=test/functional/preload.rb --load-path=test
# test/functional/preload.rb
Rails2Preload.preload_until(:load_view_paths)
Rails2Preload.initialize_rails
Bug reports, fixes, and new features are welcomed. If you'd like to contribute code, please:
-
Fork the project
-
Start a branch named for your new feature or bug
-
Run (and add to) the unit tests
-
Perform a pull request
Thanks!