Best way to test RJS in RSpec Controller specifications?

What is the best way to ensure proper RJS creation in a Controller action?

For example, I want to make sure the 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'm tired of RSpec after using it for a year. This should be a simple question, but it is one that no one answers.

I have been told repeatedly that RSpec defines behavior, and what I'm trying to do is just "test code." Highlight: some_div is behavior as far as I can tell.

+6
ruby-on-rails rspec
source share
2 answers

Can't set up a controller test to output a 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 test this more fully on the client, and the Controller test is more of a sanity check.

+4
source share

rspec provides you with the has_rjs helper, which wraps assert_select_rjs. Here are some features:

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 

Thus, this will not handle visual_effect from your question. However, the ARTS plugin does support visual effects.

http://github.com/timocratic/arts/tree/master

You can combine this with rspecs new 'spec / interop / test.

http://blog.davidchelimsky.net/2009/2/2/rspec-works-with-test-unit

+4
source share

All Articles