Skip to content

@mjtko /howto.md forked from goosetav/howto.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
prevent ttf fonts while running poltergeist

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.

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.