Want to stay on top? Ruby Weekly is a once-weekly e-mail newsletter covering the latest Ruby and Rails news.
     Feed Icon

Test Driven RJS with “ARTS: Another RJS Testing System”

By Peter Cooper / May 29, 2006

Kevin Clark looked at his options for testing his RJS (Javascript templates for Rails) templates but wasn't happy with the limited options, so he rolled his own testing system as a Rails plugin. It's called ARTS (Another RJS Testing System) and is available here. It's pretty neat, and if your app uses a lot of RJS templates, you're going to want it. Here's an example of a test using ARTS:

def test_create_rjs
  xhr :post, :create, :post => {:title => "Yet Another Post", :body => "This is yet another post"}
  assert_rjs :insert_html, :bottom, 'posts'
  assert_rjs :visual_effect, :highlight, "post_#{assigns(:post).id}"
end

Here are some general examples of how powerful it is:

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', "Here's text from insert_html"
assert_rjs :redirect_to, :action => 'list'
assert_rjs :remove, "post_1", "post_2", "post_3"
assert_rjs :replace, :bottom, 'This is something to replace'
assert_rjs :replace_html, "This is something for replace_html"
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'

Technorati Tags: ,

Other Posts to Enjoy

Twitter Mentions