Rails的一个致命弱点是没有好的方法来测试你的RJS。随着演示行为越来越复杂,无法测试它成了一个真正的问题。现在不再是这样了。
Kevin Clark发布了ARTS,这是一个测试RJS的机制。他的API简单而灵活。单一的入口点让你能够测试你生成的相当一部分RJS。以下是你可以做什么的构想:
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'
他写了一篇详尽的教程,帮助你入门和上手。