Wednesday, May 31, 2006

Testing RJS with ARTS

Posted by marcel

An Achilles’ heal of Rails is no good way to test your RJS. As the presentation behavior gets more and more sophisticated, the inability to test it becomes a real problem. Not anymore.

Kevin Clark has released ARTS, a mechanism to test RJS. His API is simple yet flexible. A single point of entry let’s you test a considerable amount of the RJS you can generate. Here’s an idea of what you can do:


  assert_rjs :alert, 'Hi!'                                                     
  assert_rjs :assign, 'a', '2'                                                 
  assert_rjs :call, 'foo', 'bar', 'baz'                                        
  assert_rjs :draggable, 'draggable_item'                                      
  assert_rjs :drop_receiving, 'receiving_item'                                 
  assert_rjs :hide, "post_1", "post_2", "post_3"                               
  assert_rjs :insert_html, :bottom, 'posts'                                    
  assert_rjs :redirect_to, :action => 'list'                                   
  assert_rjs :remove, "post_1", "post_2", "post_3"                             
  assert_rjs :replace, 'completely_replaced_div', '<p>This replaced the        
div</p>'                                                                       
  assert_rjs :replace_html, 'replaceable_div', "This goes inside the           
div"                                                                           
  assert_rjs :show, "post_1", "post_2", "post_3"                               
  assert_rjs :sortable, 'sortable_item'                                        
  assert_rjs :toggle, "post_1", "post_2", "post_3"                             
  assert_rjs :visual_effect, :highlight, "posts", :duration => '1.0'           

He’s written up an extensive tutorial to get you up and running.