# Testing RJS actions

**URL:** <https://www.ruby-forum.com/t/testing-rjs-actions/84678>\
**Category:** Rails\
**Created:** [February 6, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/testing-rjs-actions/84678 "2007-02-06T22:24:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [February 6, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/testing-rjs-actions/84678/1 "2007-02-06T22:24:18Z")

</div>

Hi all !

This is my test:  
def test\_destroy\_xhr  
Article.expects(:find).with(“1”).returns(@article = mock(“article”))  
@article.expects(:destroy).returns(true)  
delete :destroy, :id =\> 1, :format =\> :js

```
assert_template "destroy.rjs"

```

end

And my implementation:  
def destroy  
@article.destroy

```
respond_to do |format|
  format.html { redirect_to articles_url }
  format.js { render }
  format.xml { head :ok }
end

```

end

This fails spectacularly:

1. Failure:  
test\_destroy\_xhr(AuthenticatedArticlesControllerTest)  
[/home/francois/src/config/…/vendor/rails/actionpack/lib/action\_controller/assertions/response\_assertions.rb:112:in  
`assert_template' /home/francois/src/config/../vendor/rails/actionpack/lib/action_controller/assertions/response_assertions.rb:109:in `assert\_template’  
./test/functional/articles\_controller\_test.rb:84:in  
`test_destroy_xhr' /home/francois/src/config/../vendor/plugins/mocha/lib/mocha/test_case_adapter.rb:19:in `run’]:  
expecting \<“destroy.rjs”\> but rendering with 

Generally, how do we specify the type of request we are sending to the  
action ?

## Thanks !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [February 7, 2007, 3:25am UTC](https://www.ruby-forum.com/t/testing-rjs-actions/84678/2 "2007-02-07T03:25:40Z")

</div>

Is there any reason why you are not using ARTS? It would be much  
easier to test rjs if you used it.

---

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [February 7, 2007, 3:55am UTC](https://www.ruby-forum.com/t/testing-rjs-actions/84678/3 "2007-02-07T03:55:42Z")

</div>

Hi !

2007/2/6, Bala P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Is there any reason why you are not using ARTS? It would be much  
> easier to test rjs if you used it.

I don’t want to test the actual contents of the RJS. I just want to  
ensure that the proper template was rendered. That’s enough for me.

Thanks for your reply.

## Bye !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)
