16

レーキテスト中にassert_selectがこれらの厄介なhtml警告をすべて出力しないようにする方法を知っている人はいますか?あなたが知っている、このようなもののように:

.ignoring attempt to close body with div
opened at byte 1036, line 5
closed at byte 5342, line 42
attributes at open: {"class"=>"inner02"}
text around open: "</script>\r\t</head>\r\t<body class=\"inner02"
text around close: "\t</div>\r\t\t\t</div>\r\t\t</div>\r\t</body>\r</ht"

ありがとう

4

7 に答える 7

13

コードが無効な HTML を生成しているということです。バリデーターを実行して、すべての検証エラーを修正することをお勧めします。

于 2009-11-04T02:52:45.720 に答える
10

TESTOPTS v フラグを使用して、どのテストで問題が発生したかを確認できます: (bundle exec) rake test TESTOPTS="-v"

これにより、次のようになります。

test: Request the homepage should have a node list. (PresentControllerTest): .
test: Request the homepage should have the correct title. (PresentControllerTest): ignoring attempt to close div with body
  opened at byte 4378, line 89
  closed at byte 17745, line 393
  attributes at open: {"class"=>"colleft"}
  text around open: "class=\"colmid\"> \n\t\t\t<div class=\"colleft\""
  text around close: "x2.js\" ></script>\n  </body>\n</html>\n\n"
ignoring attempt to close div with html
  opened at byte 4378, line 89
  closed at byte 17753, line 394
  attributes at open: {"class"=>"colleft"}
  text around open: "class=\"colmid\"> \n\t\t\t<div class=\"colleft\""
  text around close: "</script>\n  </body>\n</html>\n\n"
.
test: Request the homepage should not set the flash. (PresentControllerTest): .
test: Request the homepage should respond with 200. (PresentControllerTest): .
于 2012-02-09T16:04:02.500 に答える
4

私が望むのは、警告がどこから来ているのかを知ることです。無効な HTML を生成するテストまたはコントローラー/アクションが指定されていないという事実は、私にとって大きな問題です。

于 2010-04-06T18:20:27.133 に答える
4

Rails の HTML スキャナは XHTML を想定しています。タグに明示的な終了タグがない HTML4 を使用している場合、この警告が表示されることがあります...解決された問題のようには見えません

于 2009-12-26T15:45:54.933 に答える
2

rails 3.0.9 と HAML 3.1.2 にアップデートした後、いくつかの問題がありました。*test_helper.rb* の次のコードで、これらの醜い出力を黙らせました。

# Wrap up the method assert_select because after updating to Rails 3.0.9 and HAML 3.1.2,
# I don't know why but it was raising warnings like this:
#     ignoring attempt to close section with body
#     opened at byte 6157, line 128
#     closed at byte 16614, line 391
#     attributes at open: {"class"=>"left-column"}
#     text around open: "->\n\n\n</span>\n</div>\n<section class='left"
#     text around close: "'1'>\n</noscript>\n</body>\n</html>\n"
# But the HTML seems to be valid (in this aspects) using a HTML validator.
ActionDispatch::Assertions::SelectorAssertions.class_eval do
  alias_method :assert_select_original, :assert_select
  def assert_select(*args, &block)
    original_verbosity = $-v # store original output value
    $-v = nil # set to nil
    assert_select_original(*args, &block)
    $-v = original_verbosity # and restore after execute assert_select
  end
end

とにかく、このようなソリューションの使用はお勧めしません。急いでいる場合にのみ使用し、他の開発者になぜそのコードのかけ離れた部分がそこにあるのかを説明する良いコメントを付けてください。

于 2011-06-23T18:33:08.810 に答える
0

私にとって、原因は有効でしたが、HAMLの形成が不十分でした。

これは私が持っていたものです:

%ul
  %li
    = link_to "Help", help_url
  - if current_user
    %li
      = link_to "Users", users_url
      = link_to "Logout", logout_url
  - else
      = link_to "Login", login_url

これは私がやりたかったことの正しいことです:

%ul
  %li
    = link_to "Help", help_url
  %li
    - if current_user
      = link_to "Users", users_url
      = link_to "Logout", logout_url
    - else
      = link_to "Login", login_url

これを追跡する最良の方法は、「開いているテキスト」と「閉じているテキスト」を注意深く調べて、テンプレートのどこで開いているかを追跡することです。

于 2011-10-04T16:25:25.587 に答える