読者です 読者をやめる 読者になる 読者になる

Poltergeistで`CoreText performance note:`などウザいwarningsを消すgem

Rubyの話。MavericksでCapybara::Poltergeistを使ってるとやたらとphantomjsに意味不明なwarningsを吐かれる。

こういう感じ。

% rspec ./spec/example_spec.rb
Run options: include {:locations=>{"./spec/requests/images_spec.rb"=>[152]}}
2014-05-01 06:59:42.547 phantomjs[9352:507] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead. 
2014-05-01 06:59:43.118 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Helvetica Neue" and got font with PostScript name "HelveticaNeue". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.118 phantomjs[9352:507] CoreText performance note: Set a breakpoint on CTFontLogSuboptimalRequest to debug.
2014-05-01 06:59:43.123 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.124 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.126 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.126 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.127 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.338 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.339 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.339 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Lucida Grande" and got font with PostScript name "LucidaGrande". For best performance, only use PostScript names when calling this API.
2014-05-01 06:59:43.630 phantomjs[9352:507] CoreText performance note: Client called CTFontCreateWithName() using name "Helvetica Neue" and got font with PostScript name "HelveticaNeue". For best performance, only use PostScript names when calling this API.
.

Finished in 4.02 seconds
1 example, 0 failures

こんなのをずっと見てると大切な人の目が傷ついてしまう。網膜が傷ついた人たちは眼科に通うことになり、その医療費は国家の財政を圧迫する。財政危機に陥った政府は増税を決行し、国民を不幸に陥れる。こうして子供たちから笑顔が失われた。もう彼らはうまい棒を10円で買うことができないのだ。

無意味なメッセージを垂れ流したままにすることは大きなリスクが潜んでいる。

このくらいなら適当にモンキーパッチを当てとけばいいんだけれど、遊びがてらgemにしてみた。

https://github.com/uiureo/poltergeist-suppressor

こうGemfileに書けば使えます。

gem 'poltergeist-suppressor'

spec_helper.rbにこう書かなきゃいけないかも。

require 'capybara/poltergeist'
require 'poltergeist/suppressor'

こんな感じで使える。

suppressor = Capybara::Poltergeist::Suppressor.new(patterns: [
  /spam spam spam spam/,
  /spamspamspamspam/
])

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, phantomjs_logger: suppressor)
end