Testing RJS actions

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://piston.rubyforge.org/

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

Hi !

2007/2/6, Bala P. [email protected]:

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://piston.rubyforge.org/