-
-
Save vlado/7713285 to your computer and use it in GitHub Desktop.
Fork of @ericboehs Poltergeist hack to silence CoreText performance notes from phantomjs My changes:
1. to is now optional parameter, if not provided @write_io is used
2. option to easily add more messages to suppress (I added this one WARNING: Method userSpaceScaleFactor in class NSView is deprecated)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Capybara::Poltergeist | |
class Client | |
private | |
def redirect_stdout(to = nil) | |
to ||= @write_io | |
prev = STDOUT.dup | |
prev.autoclose = false | |
$stdout = to | |
STDOUT.reopen(to) | |
prev = STDERR.dup | |
prev.autoclose = false | |
$stderr = to | |
STDERR.reopen(to) | |
yield | |
ensure | |
STDOUT.reopen(prev) | |
$stdout = STDOUT | |
STDERR.reopen(prev) | |
$stderr = STDERR | |
end | |
end | |
end | |
class WarningSuppressor | |
class << self | |
def write(message) | |
if message_to_supress?(message) | |
0 | |
else | |
puts(message) | |
1 | |
end | |
end | |
private | |
def message_to_supress?(message) | |
messages = [ | |
"QFont::setPixelSize: Pixel size <= 0", | |
"CoreText performance note", | |
"WARNING: Method userSpaceScaleFactor in class NSView is deprecated" | |
] | |
messsage =~ Regexp.compile("(#{messages.join('|')})") | |
end | |
end | |
end | |
Capybara.register_driver :poltergeist do |app| | |
Capybara::Poltergeist::Driver.new(app, phantomjs_logger: WarningSuppressor) | |
end | |
Capybara.javascript_driver = :poltergeist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment