Forum: Ruby on Rails [ANN] assert{ 2.0 } 0.4.8 unit-tests Ajax using assert_rjs syntax + assert_xhtml

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Phlip (Guest)
on 2009-04-05 16:43
(Received via mailing list)

assert{ 2.0 } now contains "alpha" replacements for these assertions
from the
"arts" project:

     assert_rjs_ :alert, 'This is an alert'
     assert_rjs_ :call, 'foo', 'bar', /baz/  #  matches foo("bar",
     assert_rjs_ :remove, 'offending_div'
     assert_rjs_ :replace, 'person_45', '<div>This replaces
     assert_rjs_ :replace_html, :label_7, /Top_Ranking/

Notice these assertions are not yet drop-in compatible with assert_rjs
classic -
hence the trailing _. More replacements are naturally forthcoming.

The improvement is they use racc and rkelly, which form a real
JavaScript lexer.
This solution is much better than Regexp (and better than certain lexers
I have
tried in the past!). The assertion is more accurate, so it can use both
and assert_xhtml to pin down each important detail of generated

One common Ajax scenario revolves around sending Element.update()
containing the output of View partials. These can be very complex, so
them _before_ they get into a real web browser can be mission-critical.
following test intercepts an Element.update("staff_access", "..."),
where the
"..." contains an entire <form>. (Not my idea, but you must admit it
gets the
job done!)

Everything inside the do...end blocks is assert_xhtml notation (
described here: ). The assert_rjs_ intercepted
the "..."
payload, interpreted it, and rendered it as HTML. This allows us to test
secret payload just as freely as we would have tested HTML after a
simple GET:

     aaron = staff(:aaron)
     xhr :post, :xhr_delete_staff, :staff_id =>

     assert_rjs_ :replace_html, :staff_list, /quentin/ do
       form :name => :staff_access, :verbose! => true do
         without!{ tr :id => "staff_#{ }" }

     assert{ Staff.find_by_id( == false }

The test shows :verbose! => true - use it to get a glimpse of your
actual HTML
partial, without all the JavaScript delimiters cluttering it up.

The test also shows without!{} testing that aaron did indeed disappear
from the

Both :replace and :replace_html use this syntax. If anyone needs any
"arts" assertion here - or even a new kind of JS assertion - ping me and
I will
add it.

Get assert_rjs_ with:

   gem install racc rkelly nokogiri assert2

   require 'assert2/rjs'

(Note that assert2 contains more than one reusable module, so it does
automatically require every dependency. This lets you only install the
gems you

This topic is locked and can not be replied to.