# \[ANN\] assert2 0.4.7 improves assert\_xhtml diagnostics

**URL:** <https://www.ruby-forum.com/t/ann-assert2-0-4-7-improves-assert-xhtml-diagnostics/164643>\
**Category:** Rails\
**Created:** [April 3, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/ann-assert2-0-4-7-improves-assert-xhtml-diagnostics/164643 "2009-04-03T16:23:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed8c4c/32.png) [@Phlip](https://www.ruby-forum.com/u/Phlip)\
**Post date:** [April 3, 2009, 4:23pm UTC](https://www.ruby-forum.com/t/ann-assert2-0-4-7-improves-assert-xhtml-diagnostics/164643/1 "2009-04-03T16:23:24Z")

</div>

Railsters:

Here’s an assert\_select test:

def test\_form  
assert\_renders form\_content do  
assert\_select “form[action=/forms/]”  
assert\_select “form input[type=text][name=name]”  
assert\_select “form input[type=text][name=email]”  
assert\_select “form input[type=text][name=subject]”  
end  
end

The equivalent assert\_xhtml is…

assert\_xhtml do  
form :action =\> /forms/ do # a regexp  
input :type =\> :text, :name =\> :name  
input :type =\> :text, :name =\> :email  
input :type =\> :text, :name =\> :subject  
end  
end

There’s more Ruby and less strings because assert\_xhtml uses  
Nokogiri::HTML::Builder. Any example of HTML you can build, it will  
match in  
your @response.body.

If it can’t match, it will report the example HTML it was seeking, and  
the first  
region of your code that matches the first element in your match. So the  
diagnostic for that example would report the …,  
so you can compare its contents.

Get it with gem install nokogiri assert2, and require ‘assert2/xhtml’

–  
Phlip
