David wrote:
I have some questions about testing RJS. First of all, just
generally, how important is testing RJS? It seems, that for effects
at least, if I can see that the effect is working, then that is good
enough for me?
In View testing in general, there are some overlapping rules of thumb:
- do test what you don’t want to break
- don’t test glitz (colors, shiny things, animated GIFs, etc.)
- do test that your business-side variables got embedded correctly
- do test navigation (such as links and redirect_to)
The goal is if you add new features and make a mistake the code will
break as
early as possible. But if you break glitz, you can easily see it’s
broke, and
you can easily fix it without affecting your new features.
I would like to test certain RJS redirect_to’s
however. I came across the ARTS plugin. Has anyone had any
experience using this with rails 2.2 or 2.3?
Yes; just install the plugin.
After you start using assert_rjs, look up my assert_rjs_. It’s nearly a
drop-in
replacement for the most common RJS situations, but it’s much more
powerful and
accurate.
http://groups.google.com/group/rubyonrails-talk/msg/c2fba12dd5e2735a
It does not test redirect_to, but if it did then it would not be much
more
powerful than assert_rjs Classic, so use that for now.
I saw somewhere that it
was included in 2.2, but when I try:
assert_rjs :redirect_to, :action => ‘show’
I get an unknown method error.
The documentation for the ARTS will tell you how to install a plugin.
Something
to do with script/plugin install…
assert_rjs_ is a gem, not a plugin, because test-side things don’t need
to
deploy to your server. Use assert_rjs_ when you start working with
replace_html.
–
Phlip