assert2 0.4.7 improves assert_xhtml diagnostics

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 <form action="/forms">...</form>, so you can compare its contents.

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