Friday, October 16, 2009

ignoring attempt to close foo with bar

Given:



When:



Then:



It's pretty easy, when running a ton of specs or tests, to see giant strings of dots interrupted by bizarre, enigmatic shit like this:

.........................................................................
...............................................................................
.........................................................................ignori
ng attempt to close form with br
opened at byte 12093, line 245
closed at byte 13454, line 282
attributes at open: {"class"=>"new_piece", "action"=>"/p", "method"=>"post", "id"=>"new_piece"}
text around open: "loader'></iframe>\n <form action=\"/p\" cl"
text around close: "x\" value=\"1\" />\n </br>\n <input nam"
...


It never tells you where it came from and never interferes with a spec completing. For years I thought it came from Hpricot. Nope. It comes from here:

/Library/Ruby/Gems/1.8/gems/actionpack-2.3.3/lib/action_controller/vendor/html-scanner/html/document.rb

In this arcane back alley there lurks a parser from the dark days before Treetop, just waiting for the day when a lazy blogger will quit talking shit and write some fucking code. (Or, alternatively, waiting for the day when an inspiring blogger will motivate one of his heroic readers to learn Treetop (which is awesome) and replace the old Rails HTML parser with a better one.) Until that day, you have to deal with its idiosyncrasies, one of which is overzealous warnings about HTML (indeed I think even XHTML) correctness.

It's easy to kill those warnings. Either use the verbosity special variable $-v as in this example, or run your test like this:

ruby -W0 test/whatever_test.rb

Obviously however this breaks with rake test:whatevers, and I have no idea if it works in any sense at all with RSpec. So the short-term hack: $-v reassignment FTW.

(Update: of course, the smart thing is to couch these hacks in before(:each) blocks, for RSpec, or setup and shutdown methods, for test/unit.)