[rspec-users] (x)HTML Parsing Errors, Cuc 0.2.0 + Rspec 1.2

Peer Allan Peer.Allan at canadadrugs.com
Tue Apr 7 09:47:06 EDT 2009

We are finally starting to narrow this down somewhat.  Turns out we are
getting the errors because the XHTML is invalid when it comes back from

The specific problem right now happens when attempting to validate that
there are x number of rows in a table. In a normal rspec view test this
works just fine:

response.body.should have_tag('table[class="data"]') do
  with_tag('tr', :count => 5)

But as a step in cucumber it fails. Here is the full step

Then /^there should be (\d+) data rows in the table$/ do |count|
  response.body.should have_tag('table[class="data"]') do
    with_tag('tr', :count => count.to_i)

The error is always similar to "Expected at least 30 elements matching "tr",
found 3."

Doing a 'save_and_open_page' in this step and looking at the source code we
find that all of our self-closing tags (img, link, etc.) are not closed.  If
we pause the browser while running the features and view source all those
tags are closed.

Save_and_open_page source example,

  <td><a href="edit"><img src="icon.png"></a></td>

Browser source,

  <td><a href="edit"><img src="icon.png" /></a></td>

Next we took the invalid HTML and threw it into a normal rspec view test
using the same matcher as above.  It failed the same way as the feature
does.  If we fix the invalid html by closing the unclosed tags the test

After that long winded explanation it appears that we are getting invalid
HTML back from webrat and selenium and the matchers in rspec are choking on
it.  Is there some way to get rspec to deal with this or should we dig in
and figure out why Selenium/Webrat is returning the "broken" XHTML?  We have
several people beating their heads against a wall on this one so any
suggestions are welcome.  Thanks.

For reference, we are using:
rspec 1.2.2
Rails 2.3.2
Cucumber 0.2.3
webrat 0.4.3 (patched http://github.com/mmurphy/webrat/tree/master)
Selenium client 1.2.14
Haml 2.0.9


> From: Peer Allan <Peer.Allan at canadadrugs.com>
> Reply-To: rspec-users <rspec-users at rubyforge.org>
> Date: Tue, 24 Mar 2009 13:02:31 -0500
> To: <rspec-users at rubyforge.org>
> Subject: [rspec-users] (x)HTML Parsing Errors, Cuc 0.2.0 + Rspec 1.2
> Hello all,
> I have some cucumber features that are making me scratch my head.  After
> updating the Rspec 1.2 my features are now generating thousands of "ignoring
> attempt to close tag with other tag" when I run them. The W3C validator
> tells me that the XHTML is valid.  The good news is that the tests still
> pass, but you the nice output is gone.
> I experimented with some different combinations of gems to figure it out but
> it all came down to Rspec 1.2.x.  If I remove it then the errors go away.
> This happens under both Rails 2.2.2 and Rails 2.3.2
> Has anyone else run into this?
> Peer 
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list