2012-07-06 31 views
0

Ruby on Rails有時會給您帶來惱人的「忽略嘗試用y關閉x」warnings arising from assert_select。這些警告通常是HTML無效的結果,但即使HTML有效,它們有時也會出現。在我的情況的錯誤看起來像運行ruby test/functional/my_controller_test.rb這個while:忽略嘗試使用y關閉x

..ignoring attempt to close div with h2 
    opened at byte 8551, line 207 
    closed at byte 9554, line 243 
    attributes at open: {"class"=>"my_css_class", "id"=>"object_1"} 
    text around open: " \r\n \r\n \r\n \r\n\r\n <div class=\"my_css_class" 
    text around close: "</a>\r\n  </h2>\r\n\r\n  <span" 

但沒有試圖關閉一個div用H2標籤。我嘗試了一個HTML驗證器,但沒有成功。 The -W0 parameter mentioned by Giles seems to help - ruby -W0 test/functional/my_controller_test.rb不再給出警告,但這對rake test:whatever不起作用。 -W0做什麼,以及如何避免使用它?

回答

1

有各種各樣的command line options for Ruby unit tests。 -W不屬於它們,它是純Ruby的命令行選項。正如ruby --help所說,ruby -W[level]命令行選項設置Ruby的警告級別; 0 =安靜,1 =中等,2 =詳細(默認)。 ruby -W0將警告級別設置爲無聲。

$ ruby --help 
    [...] 
    -w    turn warnings on for your script 
    -W[level]  set warning level; 0=silence, 1=medium, 2=verbose (default) 

-W標誌還激活了Ruby的「詳細」模式。 Mislav對the verbose mode有很好的解釋。在Ruby代碼中,可以使用$ VERBOSE全局變量的值來設置和測試詳細程度,它可以有3個狀態:nil(「0」),false(「1」)和true(「2」)。因此,您可以通過在您的test_helper.rb中設置

$VERBOSE = nil 

來取消對您的Test :: Unit測試的警告。對於運行RSpecs測試,您可以suppress ruby warning similarly

3

在測試助手:

class ActionController::TestCase 
    include Devise::TestHelpers 
    Paperclip.options[:log] = false 
    Mocha::Deprecation.mode = :disabled 

    # 
    # kill verbsity 
    # 
    verbosity = $-v 
    $-v = nil 

end 
相關問題