4 lines to Speed Up your Rails Test Suite on CircleCI

Paul Keen
JTWay
Published in
2 min readJan 17, 2018

--

Most of our projects have a big code base of assets which dramatically reduce not only browser page rendering but also increase passing test suites.

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots.

We found that with precompiled assets all test suite is passed faster. For some project, we got 50% improvement.

This approach shows how you can skip compilation of assets every time you run a test.

Solution

This solution for CircleCI, but you could migrate it to other CI.

Add precompile assets step with caching result into .circle/config.yml:

and here complete CircleCI config.

Benchmark

We generated simple Rails 5 project with Bootstrap and Foundation.

On this simple example we got 20% improvement.

There are 2 branches: master — with assets precompilation enabled and without-assets-precompilation without assets precompilation enabled

Extra: speedup Rails 4 system tests

On Rails 5, the asset digest is enabled by default which allows us to cache assets on a browser, but on Rails 4 you should add some changes in order to make it works.

Conclusion

This configuration allowed us to reduce and in most cases completely drop time on the assets compilation in tests.

If you enjoyed this story, we recommend reading our latest tech stories and trending tech stories.

--

--