Ignoring attempts to close x with y

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?

  • FactoryGirl: Populate a has many relation preserving build strategy
  • Using Cucumber testing for uploadify on rails 3
  • Nested form: shouldn't save if no information for child is entered
  • Writing a test for a custom FormHelper gem patch
  • Generate only tests from existing model / controllers
  • What is the state of the art/best practice for implementing ruby rake test for gems?
  • “autotest/rails doesn't exist. Aborting”
  • How to use Capybara in pure Ruby (without Rails)?
  • 2 Solutions collect form web for “Ignoring attempts to close x with y”

    In test helper:

    class ActionController::TestCase  
      include Devise::TestHelpers
      Paperclip.options[:log] = false
      Mocha::Deprecation.mode = :disabled
    
      #
      # kill verbsity
      #
      verbosity = $-v
      $-v = nil
    
    end
    

    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.

    Ruby is the best programming language in the world - Ruby on Rails.