# Howto test RJS templates?

**URL:** <https://www.ruby-forum.com/t/howto-test-rjs-templates/91247>\
**Category:** Rails\
**Created:** [April 5, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/howto-test-rjs-templates/91247 "2007-04-05T23:19:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [April 5, 2007, 11:19pm UTC](https://www.ruby-forum.com/t/howto-test-rjs-templates/91247/1 "2007-04-05T23:19:42Z")

</div>

Hi,

The following code works, but I don’t know how to test ist properly:

In the view there is a simple link\_to\_remote:

|

  
| \<%= link\_to\_remote “Create New”, :url =\> new\_category\_url %\>  
| 

Essentially, when I click on this link the “div” box gets hidden with a

| page.hide “create”

How do I test this? I have so far the following test:

| class CreateCategoriesTest \< ActionController::IntegrationTest  
| def test\_create\_category  
| get ‘categories’  
| assert\_select “#create”, “Create New”  
| xml\_http\_request new\_category\_path  
| assert\_response :success  
| # ???  
| end  
| end

How can I test, that the “#create” element is hidden?

TIA and regards,  
chris

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [April 5, 2007, 11:22pm UTC](https://www.ruby-forum.com/t/howto-test-rjs-templates/91247/2 "2007-04-05T23:22:42Z")

</div>

Christian M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can I test, that the “#create” element is hidden?

Using standard ruby functional tests, you can only check tht the  
correct  
signal was sent to the server to hide the “#create” element.

If you want to test, in the browser, that the element is really  
hidden,  
then you’ll need to use a browser-oriented testing framework like  
Selenium.

Cheers,  
Tyler

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [April 6, 2007, 2:55pm UTC](https://www.ruby-forum.com/t/howto-test-rjs-templates/91247/3 "2007-04-06T14:55:16Z")

</div>

Well, there are steps available to help test RJS, but there is no be-all  
end-all testing solution, because in the end it is javascript and you  
can’t  
run it.

Check out:

ARTS:  
[http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with-arts](http://glu.ttono.us/articles/2006/05/29/guide-test-driven-rjs-with-arts)

There’s also #assert\_select\_rjs if you’re on Rails 1.2+, but I’m not  
sure  
how to really use this:  
[http://api.rubyonrails.org/classes/ActionController/Assertions/SelectorAssertions.html#M000209](http://api.rubyonrails.org/classes/ActionController/Assertions/SelectorAssertions.html#M000209)

As an example. your simple one-line RJS is testable in ARTS:

assert\_rjs :hide, ‘create’

In the end, if you want to fully test your javascript interactions,  
you’ll  
need a browser testing solution like Selenium, or lighter-weight Systir  
+  
Watir ([http://atomicobject.com/pages/System+Testing+in+Ruby](http://atomicobject.com/pages/System+Testing+in+Ruby))

Jason
