How to speed up first request for local Rails UI tests

444 Views Asked by At

I am using spinach, Capybara, and Poltergeist together to write automated UI tests. I have been trying to speed up running tests locally. I am using Spring which helps a little with the environment loading. However, the first request (visit) to the app server that Poltergeist starts is slow because Rails has to compile the assets the first time. I have tried starting a locally server in the test environment and then doing this in my spinach env.rb file:

::Capybara.run_server = false
::Capybara.app_host = "http://localhost:#{ENV['TEST_SERVER_PORT']}"

This makes debugging difficult because the web server is running in a different process than the spinach process. Also, precompiling assets is not a good solution because I don't want to have to run it every time I am tweaking things in a JS file and then running the tests to verify my changes.

Bottom line: has anyone figured out how to make the first test server request be faster?

2

There are 2 best solutions below

1
Piotr Brudny On

You could use parallel tests for Spinach

https://github.com/grosser/parallel_tests

It probably won't solve the issue with first request but it can speed up running all tests - which still might be beneficial for you

0
Adam Eberlin On

First, I would set up rspec-retry. Second, try this in spec/rails_helper.rb:

RSpec.configure do |config|
  config.before(:all) { visit '/' if defined?(visit) }
end