
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Able Technology &#187; rspec</title>
	<atom:link href="http://www.abletech.co.nz/tag/rspec/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.abletech.co.nz</link>
	<description>Web Application Programmers and Consultants</description>
	<lastBuildDate>Tue, 10 Aug 2010 07:16:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>False-positive validation warnings</title>
		<link>http://www.abletech.co.nz/2009/03/false-positive-validation-warnings/</link>
		<comments>http://www.abletech.co.nz/2009/03/false-positive-validation-warnings/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 00:48:21 +0000</pubDate>
		<dc:creator>nigel</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.abletech.co.nz/?p=197</guid>
		<description><![CDATA[I had been getting some validation warnings when running some of my specs. The W3 validator confirmed that my xHTML was valid. ignoring attempt to close div with input opened at byte 6028, line 108 closed at byte 6131, line 109 attributes at open: {"class"=>"form_field"} text around open: "r\">\n \n\n scenarios(:abletech_pre_clicked_links).id response.headers['Content-Type'] = :xml end [...]]]></description>
			<content:encoded><![CDATA[<p>I had been getting some validation warnings when running some of my specs. The W3 validator confirmed that my xHTML was valid.</p>

<textarea name="code" class="ruby">
ignoring attempt to close div with input
  opened at byte 6028, line 108
  closed at byte 6131, line 109
  attributes at open: {"class"=>"form_field"}
  text around open: "r\"></div></div>\n    <div class=\"form_fie"
  text around close: "mit\" value=\"Log in\"></input>\n</div>\n</di"
</textarea>

<p>After some googling of the problem, it turns out there is a difference between how xhtml and html documents are handled. Essentially, you need to tell the parser that the document is xHTML rather than HTML. More details <a href="http://marklunds.com/articles/one/336">here</a>, <a href="http://weblog.jamisbuck.org/2007/1/4/assert_xml_select">here</a>, and <a href="http://dev.rubyonrails.org/ticket/1937">here</a>.</p>

<p>The solution is to tell RSpec that the document is XML based. The options given in the links above work for RUnit based tests. Taking a look at the rspec source, it is checking to see if the response is XML based by noting the Content-Type header record. So, here's the solution I used:</p>

<textarea name="code" class="ruby">
before(:each) do
  get :new, :id => scenarios(:abletech_pre_clicked_links).id
  response.headers['Content-Type'] = :xml
end
</textarea>

<p>Now, when I run my specs, it correctly parses the response as XHTML and passes validation without any warnings.</p>

<textarea name="code" class="ruby">
it 'should show two forms' do
  response.should have_tag('div.form_step', 2)
end
</textarea>

]]></content:encoded>
			<wfw:commentRss>http://www.abletech.co.nz/2009/03/false-positive-validation-warnings/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
