0

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?

Community
  • 1
  • 1
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140

2 Answers2

3

In test helper:

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

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

end
Victor Pudeyev
  • 4,296
  • 6
  • 41
  • 67
1

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 --help says, the ruby -W[level] command line option sets the warning level for Ruby; 0=silence, 1=medium, 2=verbose (default). ruby -W0 sets the warning level to silence.

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

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

$VERBOSE = nil 

in your test_helper.rb. For running RSpecs test you can suppress ruby warning similarly.

Community
  • 1
  • 1
0x4a6f4672
  • 27,297
  • 17
  • 103
  • 140