运行黄瓜规格时,红宝石1.9.2奇怪的警告

ser*_*nfo 24 ruby cucumber rvm ruby-on-rails-3

我刚刚更新了试用rails 3,使用rvm和ruby 1.9.2-p0.

当我运行我的黄瓜规格时,我会听到奇怪的警告

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string

/home/ubuntu/.rvm/gems/ruby-1.9.2-p0/gems/rack-1.2.1/lib/rack/utils.rb:16: warning: regexp match /.../n against to UTF-8 string
Run Code Online (Sandbox Code Playgroud)

我的包包含以下宝石......

Using rake (0.8.7) 
Using abstract (1.0.0) 
Using activesupport (3.0.0) 
Using builder (2.1.2) 
Using i18n (0.4.1) 
Using activemodel (3.0.0) 
Using erubis (2.6.6) 
Using rack (1.2.1) 
Using rack-mount (0.6.13) 
Using rack-test (0.5.4) 
Using tzinfo (0.3.23) 
Using actionpack (3.0.0) 
Using mime-types (1.16) 
Using polyglot (0.3.1) 
Using treetop (1.4.8) 
Using mail (2.2.5) 
Using actionmailer (3.0.0) 
Using arel (1.0.1) 
Using activerecord (3.0.0) 
Using activeresource (3.0.0) 
Using bundler (1.0.0) 
Using culerity (0.2.12) 
Using nokogiri (1.4.3.1) 
Using ffi (0.6.3) 
Using json_pure (1.4.6) 
Using rubyzip (0.9.4) 
Using selenium-webdriver (0.0.28) 
Using capybara (0.3.9) 
Using configuration (1.1.0) 
Using diff-lcs (1.1.2) 
Using trollop (1.16.2) 
Using gherkin (2.1.5) 
Using term-ansicolor (1.0.5) 
Using cucumber (0.8.5) 
Using cucumber-rails (0.3.2) 
Using database_cleaner (0.5.2) 
Using launchy (0.3.7) 
Using mysql2 (0.2.3) 
Using rspec-core (2.0.0.beta.20) 
Using rspec-expectations (2.0.0.beta.20) 
Using rspec-mocks (2.0.0.beta.20) 
Using rspec (2.0.0.beta.20) 
Using yard (0.6.0) 
Using pickle (0.4.2) 
Using thor (0.14.0) 
Using railties (3.0.0) 
Using rails (3.0.0) 
Using rspec-rails (2.0.0.beta.20) 
Using spork (0.8.4) 
Using webrat (0.7.1) 
Run Code Online (Sandbox Code Playgroud)

有谁知道如何摆脱这些警告?他们来自哪里?

Pet*_*xey 19

我在Enrico Stahn的博客文章中找到了一个很好的解决方案:http: //blog.enricostahn.com/warning-regexp-match-n-against-to-utf-8-strin

问题出现在Rack中,显然已经在1.3.0中得到修复,但您可能无法升级到它.

因此,在您升级到Rack 1.3.0之前,请config/initializers/rack_hotfix.rb使用以下内容创建该文件:

# TODO: Can be removed after updating to rack 1.3.0
module Rack
  module Utils
    def escape(s)
      CGI.escape(s.to_s)
    end
    def unescape(s)
      CGI.unescape(s)
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这对我来说很有吸引力,然后我对我的RSpec文件进行了一项待测测试,作为一个温和的提醒,一旦Rack升级就放弃初始化器.

describe ApplicationController do
  ...
  it "should not include the rack_hotfix.rb initializer after upgrading to rack 1.3.0"

end
Run Code Online (Sandbox Code Playgroud)

  • 使用Rails 3.0.10时,无法升级到Rack 1.3+,因此这是使用的诀窍!我个人不喜欢有待测试,如果你像我一样,你可以使用这些例子:`it'应该包括rack 1.3.0之前的rack_hotfix.rb初始化器"如果Rack.release.to_f <= 1.2 Rack: :Utils :: hotfixed.should be_true end end它"不应该包括rack 1.3下的rack_hotfix.rb初始化器"如果Rack.release.to_f> = 1.3期望{Rack :: Utils.hotfixed} .to raise_error end end `只需将此行添加到修补程序:`def self.hotfixed true end` (2认同)

Mik*_*tak 7

看到:

https://github.com/jnicklas/capybara/issues/87https://github.com/jnicklas/capybara/issues/243

对于这个问题的一些讨论.分辨率似乎是Capybara和Rack都需要改变一些东西才能找到一个好的解决方案.

如果我理解正确,Rack 1.3和Capybara 1.0应该可以解决这个问题.目前,Rails 3.0.8仍需要Rack~> 1.2.1,即使安装了Rack 1.3也忽略了Rack 1.3.所以我认为Rails(特别是actionpack)需要升级其依赖关系以获得一个干净的修复.


Bo *_*nes 6

将其添加到文件中features/support或将其放入env.rb文件中:

# Stop endless errors like
# ~/.rvm/gems/ruby-1.9.2-p0@global/gems/rack-1.2.1/lib/rack/utils.rb:16: 
# warning: regexp match /.../n against to UTF-8 string
$VERBOSE = nil
Run Code Online (Sandbox Code Playgroud)

这将取消这些警告,但我不确定是什么原因导致了这些警告.我也得到了他们


hju*_*ycz 6

有一个名为"escape_utils"的宝石可以解决这个问题.这是解释问题的文章的链接.

  • 我讨厌添加一个宝石和模块,只是为了解决可能是一个真正的警告.难道我们不应该坐直到补丁? (4认同)