Ruby on Rails sometimes gives you annoying “Ignoring attempts to close x with y” warnings arising from assert_select. Often these warnings are the result of invalid HTML, but sometimes they appear even if the HTML is valid. The error in my case looks like this while running ruby test/functional/my_controller_test.rb :
..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"
But there is no attempt to close a div with a h2 tag. I tried a HTML validator, but without success. The -W0 parameter mentioned by Giles seems to help – ruby -W0 test/functional/my_controller_test.rb gives no longer a warning, but this does not work for rake test:whatever. What does -W0 do, and how can you avoid using it?
There are various command line options for Ruby unit tests. -W does not belong to them, it is a command line option for pure Ruby. As
ruby --helpsays, the ruby-W[level]command line option sets the warning level for Ruby; 0=silence, 1=medium, 2=verbose (default).ruby -W0sets the warning level to silence.The -W flag also activates the “verbose” mode of Ruby. Mislav has a good explanation of the verbose mode. From within Ruby code, verbosity can be set and tested with the value of the $VERBOSE global variable, which can have 3 states: nil (“0”), false (“1”), and true (“2”). So you can suppress warning for your Test::Unit test by setting
in your
test_helper.rb. For running RSpecs test you can suppress ruby warning similarly.