Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@mjtko / forked from goosetav/
Created Nov 2, 2012

prevent ttf fonts while running poltergeist


Use Rack::SimpleEndpoint to prevent Poltergeist/PhantomJS from crashing on TTF fonts.

Create config/initializers/middleware-deny-ttf-to-phantomjs-under-test.rb:

if Rails.env.test?
  require 'rack/contrib/simple_endpoint'
  Rails.application.config.middleware.insert_after Rack::Runtime, Rack::SimpleEndpoint, /\.ttf$/ do |req, res|
    ua = req.env['HTTP_USER_AGENT']
    if ua =~ /Intel Mac OS X.*PhantomJS/
      res.status = 403
      "Denying #{req.fullpath} to #{ua}"

and add to your Gemfile (in the :test group ideally)

  group :test do
    # used for Rack::SimpleEndpoint in config/environments/test.rb (for
    # PhantomJS crash workaround)
    gem 'rack-contrib'

NOTE: This only works if assets are being served through rails while running tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.