Monday, May 22, 2006

assertions when using rjs

rjs is a pretty neat way to avoid javascript code and implement the required functionality using ruby/rails itself.

When rails comes across a rjs template, it renders the html page and inserts the JavaScript into that page and returns it to the browser for execution.

Which is good, until you figure out that the functional testing assertion framework that ships with Rails suddenly does not hold good ! Basically the asserts work on the assumption that after an action is performed, the response object holds valid HTML code which it can hook into and perform the assertions, whereas when we use rjs the respose body actually contains Javascript code too.

Came across this nice assertions plugin(rjs_assertions) which helped us test the code which had the rjs bits. Good stuff.