# Testing RJS

**URL:** <https://www.ruby-forum.com/t/testing-rjs/165025>\
**Category:** Rails\
**Created:** [April 8, 2009, 11:32am UTC](https://www.ruby-forum.com/t/testing-rjs/165025 "2009-04-08T11:32:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [April 8, 2009, 11:32am UTC](https://www.ruby-forum.com/t/testing-rjs/165025/1 "2009-04-08T11:32:16Z")

</div>

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? 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? 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.

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [April 8, 2009, 11:47am UTC](https://www.ruby-forum.com/t/testing-rjs/165025/2 "2009-04-08T11:47:33Z")

</div>

On Apr 8, 10:31 am, David [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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? 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? I saw somewhere that it  
> was included in 2.2, but when I try:

I still use arts. I don’t think it is quite true to say that 2.2/2.3  
(and I think 2.1) replaces arts, although it does have similar  
functionality via assert\_select\_rjs (don’t remember if that covers  
redirect\_to though)

I’d say testing is as important as it is elsewhere (although I would  
probably worry less about pure eye candy than about stuff that would  
impact usage (ie this div should be shown and this button enabled)).

Fred

---

<div class="post-metadata">

**Author:** ![david](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@david](https://www.ruby-forum.com/u/david)\
**Post date:** [April 8, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/testing-rjs/165025/3 "2009-04-08T14:29:28Z")

</div>

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](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
