Problem It takes a bit of time for my Rails tests to start, both RSpec and Cucumber.
Why This is because it has to load Rails before it can start running the test.
Consequences This dramatically slows down my TDD because I have to wait a few seconds after modifying my code. These seconds add up and it slows down my flow.
Solution There is a gem called Spork. It runs as a DRb server where it keeps the Rails environment between tests so you don’t have the startup cost. Both RSpec and Cucumber has command line options for the DRb.
Put into your
Then type this in your shell:
This will modify
features/support/env.rb for Cucumber and
spec/spec_helper.rb for RSpec. You just have to follow the instructions
written in those files. Basically put all the original code that was there
Spork.prefork block. This way it only gets executed once. If
things break (in my case, nothing broke), you may need to put some statements
into the other block,
Run spork. You may want to run them in separate shells.
spork rspec will run on port 8989 and
spork cucumber will run on port 8990.
You need to modify the config files for RSpec and Cucumber so they are aware of
the spork server.
For Cucumber add
--drb --port=8990 to your
config/cucumber.yml file. For
example, I put the arguments in the variable
For RSpec a line
--drb to you
When you run
rspec, it will automatically connect to the spork server and it
should be a little faster. It should work the same way with
for some reason it is throwing an exception on
SystemExit. Other than that,
it works fine.
You’ll probably notice a big difference now if you use automated testing.
autotest, you should see a significant difference in speed
in your TDD.