Back to Home

Split rspecs and cucumbers across many CI VMs with the parallel_tests gem

We recently moved to a Codeship CI at SupportBee. Unlike the CI service we were previously using, Codeship CI didn’t automatically split our Rspecs and Cucumbers across its VMs. If you’re in a similar situation, fret not. Fortunately, its easy to split rspecs and cucumbers across CI VMs with the parallel_tests gem. Here’s how it can be done. Add the parallel_tests gem to your Ruby/Rails app’s Gemfile

group :test do
  gem 'parallel_tests'
end

and install the gem

bundle install

Split rspecs across many CI VMs

To split RSpecs across say, 2 CI VMs, run the following commands. In VM 1, run

bundle exec parallel_test spec/ --verbose --type rspec -n 2 --only-group 1 --group-by filesize

In VM 2, run

bundle exec parallel_test spec/ --verbose --type rspec -n 2 --only-group 2 --group-by filesize

The parallel_tests gem splits your RSpecs into groups. The -n flag specifies the total number of groups and the --only-group flag specifies the group to run.

Split cucumbers across many CI VMs

Splitting cucumbers across CI VMs is very similar. To split Cucumbers across say, 2 CI VMs, run the following commands. In VM 1, run

bundle exec parallel_test --verbose --type cucumber -n 2 --only-group 1

In VM 2, run

bundle exec parallel_test --verbose --type cucumber -n 2 --only-group 2

Run cucumbers placed in a different directory

Rails apps typically have cucumbers in the features/ directory. However, if your cucumbers lie in a different directory, like say features/desktop/ and features/mobile/, you can modify the parallel_test command to pick cucumbers from a different directory In VM1, run

bundle exec parallel_test features/desktop features/mobile --verbose --type cucumber -n 2 --only-group 1

In VM 2, run

bundle exec parallel_test features/desktop features/mobile --verbose --type cucumber -n 2 --only-group 2

If you wish to explore further, the parallel_tests README and its help text bundle exec parallel_test --help are great resources to start with.

Built with Hugo & Notion. Source code is available at GitHub.