Skip to content

Instantly share code, notes, and snippets.

@goosetav
Created November 1, 2012 21:01
Show Gist options
  • Save goosetav/3996516 to your computer and use it in GitHub Desktop.
Save goosetav/3996516 to your computer and use it in GitHub Desktop.
prevent ttf fonts while running poltergeist

RE: teampoltergeist/poltergeist#44

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

In config/environments/test.rb, add

require 'rack/contrib/simple_endpoint'
config.middleware.insert_after Rack::Runtime, Rack::SimpleEndpoint, /\.ttf$/ do |req, res, match|
  res.status = '403'
  "I will not serve TTF fonts in test mode."
end

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

group :test do
  # used for Rack::SimpleEndpoint in config/environments/test.rb
  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