public
Created — forked from goosetav/howto.md

prevent ttf fonts while running poltergeist

  • Download Gist
howto.md
Markdown

RE: https://github.com/jonleighton/poltergeist/issues/44

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}"
    else
      :pass
    end
  end
end

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'
  end

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.