Created
April 21, 2014 13:43
-
-
Save tcmacdonald/11143121 to your computer and use it in GitHub Desktop.
Poltergeist sliencer
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 | |
prev = STDOUT.dup | |
prev.autoclose = false | |
$stdout = @write_io | |
STDOUT.reopen(@write_io) | |
prev = STDERR.dup | |
prev.autoclose = false | |
$stderr = @write_io | |
STDERR.reopen(@write_io) | |
yield | |
ensure | |
STDOUT.reopen(prev) | |
$stdout = STDOUT | |
STDERR.reopen(prev) | |
$stderr = STDERR | |
end | |
end | |
end | |
class WarningSuppressor | |
IGNORES = [ | |
/QFont::setPixelSize: Pixel size <= 0/, | |
/CoreText performance note:/, | |
/The "fb-root" div has not been created, auto-creating/ | |
] | |
class << self | |
def write(message) | |
if suppress?(message) then 0 else puts(message);1;end | |
end | |
private | |
def suppress?(message) | |
IGNORES.any? { |re| message =~ re } | |
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