Faster Rails system tests

Here’s a tip for speeding up your Rails system test suite.

You may well have a test helper to authenticate a user before continuing with your actual test. Something like this is typical:

image.png

Instead of authenticating in every system test like this, it’s possible to directly set a session cookie, saving a few steps in the process. Here’s how we did it with Capybara, Selenium and ChromeDriver (gist):

image.png

Andrey Novikov shared a gist showing a similar technique for Rspec and Devise: https://gist.github.com/Envek/9981207c79579db081897abd1afb80db

The tradeoff is that this method makes system tests less realistic. You’ll want to ensure you have good independent coverage of your authentication mechanism.

We saw a 25% reduction in overall test suite run time after we updated HEY system tests to use this method. Let me know what improvement you see!