What is the best way to ensure that the proper RJS is being generated in a Controller action?
For example, I want to ensure that a div is highlighted as such:
def new
render :update do |page|
page.visual_effect :highlight, :some_div
end
end
Rant: This is quickly becoming one of the reasons I grow tired of RSpec after using it for a year. This should be an easy question, but it's one that no one seems to have an answer for.
I've been told repeatedly that RSpec specifies behavior and what I'm trying to do here is just "test code". Highlighting of the :some_div is behavior as far as I can tell.
Is it not possible to setup a controller test for the output of the response and look for some javascript formatting?
xhr :get, :new
response.should be_success
response.should have_text("... test for JS response ...")
I would also probably use Selenium to more fully test this on the client, and the Controller test is more of a "sanity" check.
rspec gives you the have_rjs helper which wraps assert_select_rjs. Here are some specifics:
http://jonathan.tron.name/2007/11/24/rspec-and-inline-rjs
Unfortunately assert_select_rjs only covers:
:replace, :replace_html, :show, :hide, :toggle, :remove and :insert_html
So this won't handle the visual_effect from your question. However the ARTS plugin does support the visual effects.
http://github.com/timocratic/arts/tree/master
You should be able to combine that with rspecs new 'spec/interop/test'.
http://blog.davidchelimsky.net/2009/2/2/rspec-works-with-test-unit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With