We're hiring!

We're actively seeking developers for our new Detroit location. Learn more

How to Keep Font Awesome from Crashing capybara-webkit

The Short Version of the Story

As of August 2012, if you:

Look out! Serving that font to capybara-webkit will cause it to crash.

We solved the problem by creating a Rails initializer that removes fonts from Sprockets’ asset paths:

# 8/16/2012
# This is here specifically for font awesome. It causes QT and capybara-webkit
# to crash while trying to load the font.
# If you are aware of any better way to take care of this problem, let
# me know!
if Rails.env.test?
  Rails.application.config.assets.paths.reject! { |path| path.to_s =~ /fonts/ }
end

The Long Version

We recently brought Font Awesome into our Rails project via Font-Awesome-SASS-Enhanced. It certainly proved itself awesome, but had the side effect of causing our test suite to crash. According to the chatter in this github thread, capybara-webkit and QT are crashing while trying to load the font.

I took inspiration from some of the solutions in that thread to come up with a workaround: I created an initializer that removes font assets from Sprockets’ asset path list. This means that when the test browser requests a font, the server won’t return it, and the test browser will fall back on a font it already has.

# 8/16/2012
# This is here specifically for font awesome. It causes QT and capybara-webkit
# to crash while trying to load the font.
# If you are aware of any better way to take care of this problem, let
# me know!
if Rails.env.test?
  Rails.application.config.assets.paths.reject! { |path| path.to_s =~ /fonts/ }
end

Problem avoided.

I’m uncertain about the long-term effects of removing all custom fonts when the tests are running. I think it’s ok, as browsers should fall back, but I’m nervous I’ve introduced a lurking demon into the test harness. Time will tell.

Matt Fletcher (73 Posts)

Matt is a software product developer and designer with Atomic Object.

This entry was posted in Ruby and tagged , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.