Ruby On Rails Lesson
Speeding up Tests with Spork
When running bundle exec rspec, you may have noticed that it takes several seconds just to start running the tests, but once they start running they finish quickly. This is because each time RSpec runs the tests it has to reload the entire Rails environment. The Spork test server17 aims to solve this problem. Spork loads the environment once, and then maintains a pool of processes for running future tests. Spork is particularly useful when combined with Guard (Section 3.6.2).
The first step is to add the spork gem dependency to the Gemfile (Listing 3.35).
Then install Spork using bundle install:
Next, bootstrap the Spork configuration:
Nowwe need to edittheRSpec configuration file, located in spec/spec_helper.rb, so that the environment gets loaded in a prefork block, which arranges for it to be loaded only once (Listing 3.36).