Skip to content
andrewdsmith edited this page Mar 6, 2012 · 9 revisions

As of release 0.3.10 Cucumber has a new --drb switch.

This switch lets you offload the startup time of your code to Spork. This is very handy in situations where you only want to run a few scenarios (typically the ones you are working on right now).

It’s important to realise that Spork doesn’t actually make your scenarios run faster. In fact, they will run slower because of the DRb overhead. What does become faster is startup time (the duration before the first feature runs). Typically this is the time it takes to load all the framework code and other rubygems your application depends upon.

This means that for just a few scenarios, you will see an improvement in time, but if you are running N scenarios you will see a degradation. The value of N depends on your project. The more code that gets loaded at startup, the bigger N will be. It’s probably around 10-20 for most projects.

Ok – now that you understand the implications you can start Spork and have it preload your application in a separate process.

The easiest way to set things up is to pass --spork to the cucumber generator when bootstrapping Cucumber for Ruby on Rails. When you have set up your spork script, start the spork server:

spork cuc

Spork listens for DRb connections, and when you run cucumber with --drb the features will run inside the Spork server instead, and none of your application code will be loaded in the ruby interpreter you run Cucumber with.

Spork provides two simple hooks for preloading your application – one for framework/stable code (Spork.prefork) and one for the code that you write and change often (Spork.each_run).

Keep in mind that all hooks need to be defined in the Spork.each_run block. Using Spork works great for Ruby on Rails, which can take a while to load, but --drb and Spork aren’t tied to Rails at all.

The new --drb switch also works great alongside Cucumber’s Autotest integration. Just add --drb to your autotest profile in cucumber.yml. This will give you much faster feedback from Autotest.

If you need to run spork on a port other than the default (you’re on a multi-user system, or you’re testing more than one application), you may use the --port switch to specify a different port.

spork cucumber --port 12345 &
cucumber --drb --port 12345

Alternately, you may specify the environment variable $CUCUMBER_DRB and use spork and cucumber as normal.

Although Spork was in mind when the --drb switch was added it is important to realize that all that was added
to Cucumber was a DRb client. Any DRb server that adheres to this protocol can be used with Cucumber’s --drb switch.

While Spork is geared towards removing the load time to give you a faster feedback loop you could just as easily use this client with a server that distributes your features to run in parallel. Someone just needs to write such a server – hint hint.

Worth checking out is also testjour – a distributed runner for Cucumber. It’s currently not related to Spork.

For a closer look on how to install and configure your environment to use Spork in a Rails application, there’s a nice screencast on BDDCasts: Using Spork to speed up RSpec and Cucumber.

Clone this wiki locally