2012年3月23日
Railsテスト時のrack警告"warning: regexp match /.../n against to UTF-8 string"を消す方法
Rails 3.1以前のバージョンなら多分テスト実行時にこういう警告が出ることがあるかもしれません。
gems/rack-1.2.5/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string
このうるさい警告を消す方法を紹介します。
解決方法
rspecを使う場合はspec/spec_helper.rbに下記コードを最後に追記してください。
This file contains hidden or 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
RSpec.configure do |config| | |
# ... | |
end | |
# quick hack to get Rack to be quiet about "warning: regexp match /.../n against to UTF-8 string" until we upgrade to Rails 3.1 with Rack 1.3 | |
module Rack | |
module Utils | |
def escape(s) | |
CGI.escape(s.to_s) | |
end | |
def unescape(s) | |
CGI.unescape(s) | |
end | |
end | |
end |
原因
Rack1.3からは解決できたらしいですが、Rails 3.1以前を使うならとりあえずこの方法で回避してもいいかと。
詳しくは:https://github.com/rack/rack/issues/41