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

David Chelimsky dchelimsky at gmail.com
Tue Apr 7 10:25:02 EDT 2009

On Tue, Apr 7, 2009 at 8:47 AM, Peer Allan <Peer.Allan at canadadrugs.com> wrote:
> 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
> webrat/selenium.
> 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)
> end
> 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)
>  end
> end
> 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,
> <tr>
>  <td>Content</td>
>  <td><a href="edit"><img src="icon.png"></a></td>
> </tr>
> Browser source,
> <tr>
>  <td>Content</td>
>  <td><a href="edit"><img src="icon.png" /></a></td>
> </tr>
> 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
> passes.
> 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.

This is going to sound a lot like buck-passing, but the have_tag
matcher in rspec-rails is a wrapper for Rails' assert_select, which is
what does the actual parsing. So if the fix is to make it more
tolerant of poorly formatted XHTML, that's going to have to go to the
rails project.

> 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
> Peer
>> 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
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list