Forum: Ruby on Rails [ANN] assert2 0.4.7 improves assert_xhtml diagnostics

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Phlip (Guest)
on 2009-04-03 18:23
(Received via mailing list)
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'

--
   Phlip
This topic is locked and can not be replied to.