utilities that make unit testing easier
Working with an application that requires many resources and services might take a while to initialize. Such is our Kontera Advertisers Center. When working in development mode it is nice to be able to run our Rspec tests. But although the test themselves run fast (about 300 tests in ~30 seconds), loading the environment takes 40 seconds. To ease the pain of waiting I use a spork!

Image taken from http://imgs.xkcd.com/comics/forks_and_spoons.png
Spork makes running unit tests faster by shortening the loading time. It requires some modifications to your spec_helper.rb file: (example from AC spec/spec_helper.rb)
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it to take effect.
ENV["RAILS_ENV"] = 'ci'
$LOAD_PATH.push File.join(File.dirname(__FILE__),"..")
require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/rails'
end
Spork.each_run do
# This code will be run each time you run your specs.
Dir[File.expand_path(File.join(File.dirname(__FILE__),'/spec_helpers','**','*.rb'))].each {|f| require f}
end
To use Spork: Install spork gem:
gem install spork
Bootstap spork: (then modify your spec_helper)
spork --bootstrap
Run spork in the background: (from application root)
spork &
Add --drb to the running test, for example:
spec spec/models/permissions.rb -c -fn --drb

Nimrod Beithalachmi
Reader Comments