On a project recently, our full test suite began to crawl (taking ~9 minutes
instead of less than 1) on our local machines running OS X but ran normally on
CI. This slowdown took our productivity to near zero. We discovered our
Capybara specs with
js: true set were the culprit but we couldn’t figure out
We needed to get more information from the tests so we set the
debug mode. When using Capybara Webkit, that change looked like:
After this change, when running the tests, we saw more verbose log output
revealing that the tests were running slowly due to loading external Typekits.
The specific problem was the following line in our
We didn’t need to load fonts in specs so we made the below change as our first solution to the problem:
This update did the trick and we were back to sub-1-minute full suite runs. But, editing the layout only for the tests felt dirty.
Capybara Webkit provides a handy way to limit specific external requests.
Instead of wrapping the
script tag in a conditional we did the following in
spec/rails_helper.rb to block calls to particular URLs:
config.before(:each, js: true) do page.driver.browser.url_blacklist = ["http://use.typekit.net"] end
With this configuration in place all requests to the listed URLs return a response with an empty body and status of
200. We could then remove the environment check from the layout. Blacklisting
the URL at the request level provided the added benefit of a more thorough
integration test. The environment check approach could allow for missing methods
or typos within the
unless block that would not be surfaced until in
Read the documentation to learn how to get more verbose logs from Capybara.